google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 WAP Program to Add All the Digits of a Number given by a User

WAP Program to Add All the Digits of a Number given by a User

0
/* C program to accept an integer & find the sum of its digits */


#include <stdio.h>
#include <conio.h>
 
void main()
{
long num, temp, digit, sum = 0;
 
printf("Enter the number \n");
scanf("%ld", &num);
    temp = num;
while (num > 0)
{
        digit = num % 10;
        sum = sum + digit;
        num /= 10;
}
printf("Given number = %ld\n", temp);
printf("Sum of the digits %ld = %ld\n", temp, sum);
}

Output:

Enter the number
300
Given number = 300
Sum of the digits 300 = 3
 
 
Enter the number
16789
Given number = 16789
Sum of the digits 16789 = 31

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top