#include<stdio.h>
void rec(int n, int cal);
int main( )
{
int n,cal=0;
printf("Enter the number");
scanf("%d",&n);
rec(n,cal);
return 0;
}
void rec(int n, int cal)
{
int i;
if(n==0)
printf("sum of digits is %d",cal);
if(n>0)
{
i=n%10;
n=n/10;
cal=cal+i;
rec(n,cal);
}
}
void rec(int n, int cal);
int main( )
{
int n,cal=0;
printf("Enter the number");
scanf("%d",&n);
rec(n,cal);
return 0;
}
void rec(int n, int cal)
{
int i;
if(n==0)
printf("sum of digits is %d",cal);
if(n>0)
{
i=n%10;
n=n/10;
cal=cal+i;
rec(n,cal);
}
}
0 Comments