A five digit positive integer ( less than 32767 ) is entered through the keyboard write a function to calculate sum of digits of the five digit number by using recursive function.
#include <stdio.h>
#include <conio.h>
int rsum ( int ); /* Function Prototype Declaration */
void main ( )
{
int rs;
int n;
clrscr ( );
printf("\n\n\t\t Enter a number...:"); scanf("%d", &n);
rs = rsum ( n ); /* Function calling */
printf("\n\n\t\t Sum of Digits...: %d", rs);
getch ( );
}
int rsum ( int num ) /* Function Definition */
{
int sum = 0, rem;
if ( num != 0 )
{
rem = num % 10;
sum = rem + rsum ( num / 10 );
}
return sum;
}
Click here to contact us
#include <stdio.h>
#include <conio.h>
int rsum ( int ); /* Function Prototype Declaration */
void main ( )
{
int rs;
int n;
clrscr ( );
printf("\n\n\t\t Enter a number...:"); scanf("%d", &n);
rs = rsum ( n ); /* Function calling */
printf("\n\n\t\t Sum of Digits...: %d", rs);
getch ( );
}
int rsum ( int num ) /* Function Definition */
{
int sum = 0, rem;
if ( num != 0 )
{
rem = num % 10;
sum = rem + rsum ( num / 10 );
}
return sum;
}
Click here to contact us
No comments:
Post a Comment