/*
Program for sum of the digits of a number.
*/
#include<conio.h>
#include<stdio.h>
int sumDigit(int);
int main()
{
int a=123;
clrscr();
printf("\nEnter A Number.");
scanf("%d",&a);
printf("\nSum Of Digits In %d Is %d",a,sumDigit(a));
return 0;
}
int sumDigit(int number)
{
if(number>0)
{
int digit = number%10;
number = number/10;
return digit+sumDigit(number);
}
return 0;
}
No comments:
Post a Comment