Sum of 5 digits using recursion
A 5-digit positive integer is entered through the keyboard,
write a function to calculate sum of digits of the 5-digit number Using
recursion
#include<stdio.h>
void sum(int m)
void main(){
int x,s;
printf("\nInput a 5 digit number");
scanf("%d",&x);
s=sum(x);
printf("\nThe sum of the digits is %d",s);
}
void sum(int m)
{
if(m==0)
return 0;
else
return(m%10+sum(m/10));
}
Comments
Post a Comment