Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Friday, September 30, 2022

C program to calculate and print the sum of digits using function.

 C program to calculate and print the sum of digits using function.


#include<stdio.h>

int sum(int n)

{

     if(n==0)

          return 0;

     else

          return(n%10+sum(n/10));

}

int main()

{

     int x,y;

     printf("Enter any Number : ");

     scanf("%d",&x);

     y=sum(x);

     printf("\nSum of Digits : %d",y);

     return 0;

}


Output:



No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages