C Program to find SUM of Digit using Function

C Program to find SUM of Digit using Function, C Function to SUM digit, UDF for sum of digit in C



#include
#include
void sum(int n)
{
int sum,n1;
sum=0;
for(;n>0;)
{
n1=n%10;
sum=sum+n1;
n=n/10;
}
printf("sum of digits=%d",sum);

}
void main()
{
int x;
clrscr();
printf("enter the value of n");
scanf("%d",&x);
sum(x);
getch();
}





No comments:

Post a Comment