source code name: RECSUM.C
#include<stdio.h>
int sumrec(int n)
{
int sum=0;
int d;
d=n%10;
sum=sum+d;
if(n==0)
return 0;
else
{
sum=sum+sumrec(n/10);
}
return sum;
}
int main()
{
int n,s;
//clrscr();
printf(" enter any no: \n");
scanf("%d",&n);
s=sumrec(n);
printf(" sum of digits: %d ",s);
//getch();
return 0;
}
output:
enter any no: 12345
sum of digits: 15
enter any no: 22222
sum of digits:10
enter any no: 12211
sum of digits:7
0 Comments
Post a Comment