0
2.4kviews
Write a program to calculate sum of digits of a given n digit number using recursion.

Mumbai University> FE > Sem 2> STRUCTURED PROGRAMMING APPROACH

Marks: 8 M

Year: Dec 2016

1 Answer
0
132views
#include<stdio.h>
#include<conio.h>
int sum(int a);
main();
{
int num,result;
printf(“Enter a Number: ”);
scanf(“%d”,&num);
result=sum(num);
printf(“Sum of digit is %d”,result);
getch();
}

int sum(int a)
{
if(num!=0)
{
    return(num%10+sum(num/10));
}
else
{
    return 0;
}
}

Output:
Enter a number: 1234
Sum of digit is 10
Please log in to add an answer.