Saturday, March 1, 2014

To find the sum of the entered number using function only


By on 5:21 AM

In this page I have written the program to find the sum of the entered number using function but not recursion:
It can be done in this way:

The main source code is given below:

#include<stdio.h>
#include<conio.h>
int sum (int);
int main()
{
int num,x;
printf("enter the number whose sum is to be find");
scanf("%d",&num);
x=sum(num);
printf("the sum of the entered number is %d",x);
getch();
}
int sum(int n )
{
int r,s=0;
while (n!=0)
{
r=n%10;
s=s+r;
n=n/10;
}
return s;
}

About Authors

Aakash and Shreeram are owners of this website. Both are engineering student. Aakash is studying computer engineering and has passion with blogs and love to play with it while Shreeram is studying civil engineering and has dream of implementing technology in practical life.

0 comments :

Post a Comment