//sum of digits of given number using Recursion
#include<stdio.h>
#include<conio.h>
main()
{
int a,n;
clrscr();
printf("\n enter any number:");
scanf("%d",&n);
a=sumdig(n);
printf("\n sum of digits of the number =%d",a);
getch();
}
sumdig(int num)
{
static int sum;
int a,b;
a=num%10;
b=(num-a)/10;
sum=sum+a;
if(b!=0)
sumdig(b);
else
return(sum);
}
#include<stdio.h>
#include<conio.h>
main()
{
int a,n;
clrscr();
printf("\n enter any number:");
scanf("%d",&n);
a=sumdig(n);
printf("\n sum of digits of the number =%d",a);
getch();
}
sumdig(int num)
{
static int sum;
int a,b;
a=num%10;
b=(num-a)/10;
sum=sum+a;
if(b!=0)
sumdig(b);
else
return(sum);
}
No comments:
Post a Comment