pages

Wednesday, 2 June 2021

c-program to calculate the sum of the digits of the number | c-programming

 Program to calculate the sum of the digits of the number in c-programming.

In this program we will now takes input form the user and calculate the sum of the digits of the number in c-programming languages.

#include<Stdio.h>
int sum(int n);
main()
{
    int x,s;
    printf("enter the number");
    scanf("%d",&x);
    s=sum(x);
    printf("the sum of the number is %d",s);
    getch();
}
int sum(int n)
{
    int result;
    if(n==0)
        return(0);
    result=n%10+sum(n/10);
    return(result);
    getch();
}

output:-


                                  


For more c-programming:-




1 comment: