You're online now.

Hurray! you are online now.

# Sum of digit calculate program

We can get the sum of the digit by adding every digits of the given number forgetting the place of value of the digit.
For Example:
If we have the number: 382.
We can can calculate the digit sum as 3 + 8 + 2 = 13.

## Algorithm of the sum of digit

1. Get number by user.
2. Calculate the remainder of the number.
3. sum of the remainder.
4. Divide by the 10 (for remove the digit).
5. REPEAT the step 2, step 3 and step 4 while the number is not equal to zero (n ≠ 0).

## Sum of digit program in c programming language

``````#include<stdio.h>
int main(){
int n;
printf("Enter the number : ");
scanf("%d", &n);
int sum = 0, x;
while(n!=0){
x = n % 10;
sum = sum + x;
n = n / 10;
}
printf("Sum is : %d",sum);
return 0;
}
``````

## Sum of digits in c++

``````#include<iostream>
using namespace std;
int main(){
int n;
cout<<"Enter the number : ";
cin>>n;
int sum = 0, x;
while(n!=0){
x = n % 10;
sum = sum + x;
n = n / 10;
}
cout<<"Sum is : "<<sum;
return 0;
}
``````
🖤 0