Program to calculate the sum digits of a number in C
#include
#include
main()
{
int x,n;
printf("Enter a number :");
scanf("%d",&n);
x=sum_digit(n);
printf("%d",x);
}
int sum_digit(int n)
{
int s=0;
while(n>0)
{
s=s + n%10;
n=n/10;
}
return s;
}
#include
main()
{
int x,n;
printf("Enter a number :");
scanf("%d",&n);
x=sum_digit(n);
printf("%d",x);
}
int sum_digit(int n)
{
int s=0;
while(n>0)
{
s=s + n%10;
n=n/10;
}
return s;
}
No comments
Post a Comment