Sum Of Digits Of A Number

C Program to Find Sum of Digits of a Number 

In this C program we will allow the user enter any number and then we will divide the number into individual digits and adding those individuals (Sum=sum+digit) digits using While Loop.

Ex:-  number is 231456

 2+3+1+4+5+6=21

sum of digit of a given number is 21

sum of digits of a number in c

Working:-

Step 1: Start 

Step 2: Ask the user to insert an integer as an input. 

Step 3: Divide the integer by 10 in order to obtain quotient and remainder. 

Step 4: Increase the new variable with the remainder received in the above step 

Step 5: Repeat the above steps with the quotient till the value of the quotient becomes zero. 

Step 6: Printf the output or sum 

Step 7: Stop 

Sum of digits

programming:-

/* C program to take a number & calculate the sum of its numbers */ 
#include<stdio.h> int main()
{ int no, temp, digit, sum = 0; printf ("Insert a number \n"); scanf ("%d", &no); temp = no; while (no > 0) { digit = no % 10; sum = sum + digit; no /= 10; } printf("Given number = %d\n", temp); printf("Sum of the numbers %d = %d\n", temp, sum); return 0;
}

Output

Insert a number 
4598
Given number = 4598
Sum of the numbers 4598 = 26