-
Notifications
You must be signed in to change notification settings - Fork 7
/
armstrong_3digit.c
49 lines (36 loc) · 1.28 KB
/
armstrong_3digit.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This is the program for checking the 3 digit number for Armstrong or Not without using loop
/* 3 digit Armstrong number is the sum of cube of the digits of the number. if it is of 2 digit then sum of
square of the digits and so on.
example 153 = 1*1*1 + 5*5*5 + 3*3*3 = 153 it is armstrong number.
*/
/* Sample Input :
Enter the 3 digit number : 150
Sample Output :
The number is Not Armstrong
*/
#include <stdio.h>
void main()
{
int num ,n,cube=0 ,flag; // variable declaration
printf("Enter the 3 digit number :");
scanf("%d",&num); // input number
flag = num;
n = num % 10; // separate the unit place and store it in variable 'n'
cube = cube + n*n*n ; // add the cube of the digit to variable cube
num = num/10; // divide the number by 10 to convert it into 2 digit.
// For 3 digit number repeat this process for 3 times
n = num % 10;
cube = cube + n*n*n ;
num = num/10;
n = num % 10;
cube = cube + n*n*n ;
num = num/10;
if (cube == flag)
{
printf("The number is Armstrong ");
}
else
{
printf("The number is Not Armstrong");
}
}