Below is C program to Sum of digit by Recursion .
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /* 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