/*****************<soeasyprograms.blogspot.in>******************/
/*Program to find sum of digits of a number using recursive function*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
int rec (int);
clrscr();
printf("Enter the number whose sum of digits is required\n");
scanf("%d",&n);
i=rec(n);
printf("Sum of digits of given number is %d",i);
getch();
}
int rec( int n)
{
int i,sum;
while(n>0)
{
i=n%10;
n=n/10;
sum=i+rec(n);
return(sum);
}
}
/*****************<soeasyprograms.blogspot.in>******************/
No comments:
Post a Comment