Tuesday, 7 May 2013

Program In C To Find Sum Of Digits Of A Number Using Recursion

#include<stdio.h>
#include<conio.h>
int fun(int num)
{ int rem,sum;
if(num==0)
return 0;
else
{ rem=num%10;
sum=rem+fun(num/=10); }
return sum;
}
void main()
{ int n,sod;
clrscr();
printf("Enter Number: ");
scanf("%d",&n);
sod=fun(n);
printf("Sum Of Digits Is: %d",sod);
getch();
}

1 comment:

  1. that's really gud.
    for simple program to find sum of digits of a number visit
    http://codingloverlavi.blogspot.in/2013/05/sum-of-digits-of-number.html

    ReplyDelete