Friday 23 September 2016

Sum of digit by Recursion

/* Sum of digit by recursion */

#include<stdio.h>
int sod(int);

int main()
{
int i;
printf(" Type any value : ");
scanf("%d",&i);
printf("Sum of digit : %d",sod(i));
return 0;
}

int sod(int n)
{
if(n<1)
return 0;
return(n%10+sod(n/10));
}

No comments:

Post a Comment

Featured post

The Thrill of Programming: Exploring the Satisfaction Behind the Code

Different individuals find satisfaction in programming for various reasons. Here are some common factors that tend to bring satisfaction to ...