# Sum of Digits Using While Loop Statement in C

Dec 25, 2021

Machine Problem

Design a program that will ask the user to give a number and then the program will compute the sum of all the digits of the given number using while loop statement.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My mobile number here in the Philippines is 09173084360.

Program Listing

/* Problem No. 1

Design a program that will ask the user to give a number and then
the program will compute the sum of all the digits of the given
number using while loop statement.

Solution

sum_digits.c
Author   : Jake Rodriguez Pomperada, MAED-IT, MIT
Science Research Specialist II Technological University of the Philippines Visayas
Address  : Capt. Sabi Street, Talisay City, Negros Occidental, Philippines
Tool     : Dev C++ Version 5.11
Date     : December 25, 2021   9:46 PM Saturday
*/

#include <stdio.h>

int main()
{
long int num=0, r=0, sum=0;
printf("\n\n");
printf("\tSum of Digits Using While Loop Statement in C");
printf("\n\n");
printf("\tGive a Number : ");
scanf("%d",&num);
sum = 0;
while (num !=0){
r = num % 10;
sum+=r;
num/=10;
}
printf("\n");
printf("\tThe total sum of the digits is %d.",sum);
printf("\n\n");
printf("\t\t End of Program");
printf("\n\n");
}