C program to calculate and print the sum of digits using function.
#include<stdio.h>
int sum(int n)
{
if(n==0)
return 0;
else
return(n%10+sum(n/10));
}
int main()
{
int x,y;
printf("Enter any Number : ");
scanf("%d",&x);
y=sum(x);
printf("\nSum of Digits : %d",y);
return 0;
}
No comments:
Post a Comment