Find The Sum of Digits of a Given Number source codeThis snippet submitted by SHINE AIYYAPPAN on 2012-06-29. It has been viewed 1619 times.Rating of 8.1 with 17 votes #include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
long int Sum_of_Dig(long int Number)
{
static long int sum=0;
if (Number==0)
{ return(sum);
}
else
{
sum=sum+Number%10+Sum_of_Dig(Number/10);
}
return(sum);
}
int main()
{
long int Num=0,Sum_dig=0;
printf("\n Enter Number : ");
scanf(\"%ld\",&Num);
Sum_dig=Sum_of_Dig(Num);
printf("\n Sum Of Digits :%ld ",Sum_dig);
return(0);
}
More C and C++ source code snippets Add a snippet! |