PROGRAM:
#include<stdio.h>
int sum(int n,int s)
{
if(n<10) return n;
else
return
(n%10)+sum(n/10,s);
}
main()
{
int n,s=0;
printf("\nEnter a
Number\n");
scanf("%d",&n);
s=sum(n,s);
printf("\nThe sum of digits %d is
%d\n",n,sum(n,s));
}
OUTPUT:
Enter
a Number 46612
The sum of digits 46612 is 19
No comments:
Post a Comment