/* * To input two sorted arrays ,merge them into a third array,which should also be sorted * @author-Karan Narain(karan@iitk.ac.in) * */ #include //sum is the function which recursively calculates the sum of the digits of the number n int sum(int n) { if(n==0) return 0; else return (n%10+sum(n/10)); } //sumrec is the function which recursively calculates the sum of digits till the sum becomes a single-digit number,by calling sum() void sumrec(int n) { printf("The sum of digits of %d is",n); n=sum(n); printf(" %d\n",n); //If the sum has more than 1 digit,make a recursive call if(n/10!=0) sumrec(n); else return; } int main() { int n,s; printf("Enter the number\n"); scanf("%d",&n); sumrec(n); return 0; }