C Program To Find The Sum of Digits of An Integer Using Recursion - Another Logic

#include<conio.h>
#include<stdio.h>

int sumdigit(int n);

void main()
{
int num;
printf("Enter Any Number  : ");
scanf("%d",&num);

printf("\n Sum   : %d",sumdigit(num));

getch();

}

int sumdigit(int n)
{
  if(n/10==0)
return n;
else
  return n%10+sumdigit(n/10);

}
Share on Google Plus

About Akash Manhas

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment