The Program in C that calculates the sum of digits of 3-Digit number is given below:
#include <stdio.h>
int main() {
int num, sum = 0, rem;
printf("Enter a three digit number: ");
scanf("%d", &num);
while (num > 0) {
rem = num % 10;
sum += rem;
num /= 10;
}
printf("Sum of digits: %d", sum);
return 0;
}
Output:
Enter a three-digit number: 026
Sum of digits: 8
Pro-Tips💡
This program takes a three-digit number as input and uses a while loop to find the sum of its digits.
The remainder of the number when divided by 10 is added to the sum and then the number is divided by 10 in each iteration. Finally, the sum of digits is displayed as output.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.