A 5-digit positive integer is entered through the keyboard, write a function to calculate sum of digits of the 5-digit number Using recursion
code obtained from: https://www.blogger.com/comment.g?blogID=20225658&postID=115134493576072577 -->comment by (rahul sahay)
void main()
{
int f,l;
printf("\nInput a 5 digit number");
scanf("%d",&f);
l=sum(f);
printf("\nThe sum of the digits is %d",l);
}
sum(int n)
{
if(n==0)
return 0;
else
return(n%10+sum(n/10));
}
Subscribe to:
Post Comments (Atom)
Thanx..
ReplyDeleteNot bad,thanks
ReplyDeletethanx
ReplyDeleteThanx Buddy
ReplyDeleteThanx Buddy
ReplyDeleteit says main must return int
ReplyDeleteUse int main () instead of void main ().
Deletegood
ReplyDeletegood but try to improve it.
ReplyDeletesame 2 u buddy
ReplyDelete