Friday, September 23, 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

B
BEING CODERS

Take Your Coding Journey Further!

Find more coding tutorials, technology insights, programming guides, and practical knowledge. Choose your reading experience below!

✦ Keep Learning. Keep Building. Keep Coding. ✦