# C C++ program to find sum of digits of given number

## C C++ program to find sum of digits of given number

C Language में उपलब्ध Operators और इनके विभिन्न प्रकारो को जानने के लिए देखें—Operators in C

C-Language में Operator Precedence और Associativity Rule क्या होता है जानने के लिए देखें— Precedence and Associativity in C

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

### C program to find sum of digits of given number

``````#include<stdio.h>
int main()
{
int num,rem,sum=0;
printf("Enter a number: ");
scanf("%d",&num);
while(num!=0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf("Sum of digits = %d",sum);
return 0;
}``````

### C++ program to find sum of digits of given number

``````#include<iostream>
using namespace std;
int main()
{
int num,rem,sum=0;
cout<<"Enter a number: ";
cin>>num;
while(num!=0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
cout<<"Sum of digits = "<<sum;
return 0;
}``````

### Output of C C++ program to find sum of digits of given number

```Enter a number: 472
Sum of digits = 13```
```Enter a number: 281
Sum of digits = 11 ```

### Similar looping and Iterative programs in C C++

Share it to: 