Find The Sum of Digits of a Given Number source code

This snippet submitted by SHINE AIYYAPPAN on 2012-06-29. It has been viewed 3857 times.
Rating of 8.2 with 28 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!