forked from saurav2401/C_Basics
-
Notifications
You must be signed in to change notification settings - Fork 1
/
3digit_sum.c
32 lines (24 loc) · 870 Bytes
/
3digit_sum.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// This is the program for finding the sum of digits 3 digit number
/* Sample Input :
Enter the 3 digit number : 123
Sample Output :
The sum of 3 digit number is : 6
*/
#include <stdio.h>
void main()
{
int num ,n,sum=0; // variable declaration
printf("Enter the 3 digit number :");
scanf("%d",&num); // input number
n = num % 10; // separate the unit place of the number
sum = sum + n ; // add it to sum
num = num/10; // remove it unit place
// For 3 digit number repeat this step for 3 times.
n = num % 10;
sum = sum + n ;
num = num/10;
n = num % 10;
sum = sum + n ;
num = num/10;
printf("The sum of 3 digit number is : %d",sum); // output
}