Skip to main content

Sum of 5 digits using recursion

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

Popular posts from this blog

C Program to print the pattern

C Program to print the pattern X X Y X Y Z ........................................................................................ #include<stdio.h> #include<conio.h> void main () { int i , j ; for ( i= 88 ; i< 91 ;i ++) { for ( j = 88 ;j <= i ; j ++) { printf ( "%c" , j );                    }           printf ( "\n" ); } getch (); } ........................................................................................ OUTPUT

Deen Dayal Upadhyay Gorakhpur University RESULTS

DDU Gorakhpur results chahiye to yaha click kare                                                                       RESULTS  

Computer Science B.Sc2nd Practical 2016

             Deen Dayal Upadhyaya Gorakhpur University                            Computer Science B.Sc2nd Practical 2016