#include "stdio.h"
#include "conio.h"
int sum(long int);/* Function Prototype */
void main()
{
long int num;
int result;
printf("Enter Number :");
scanf("%ld",&num);
result = sum(num); /* Function Call */
printf("Sum of Digits - %d",result);
getch();
}
int sum(long int n) /* Function Definition */
{
int digit;
if(n == 0)
return 0;
else
{
digit = n%10;
return digit + sum(n/10); /* Recursive Statement */
}
}
Saturday, December 5, 2009
PROGRAM TO FIND THE SUM OF DIGITS USING RECURRSION
Labels: Recurrsion
Posted by Unknown at 11:23 PM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment