Skip to content

Commit 0b746c8

Browse files
Merge pull request DHEERAJHARODE#2624 from Mustafa1765/patch-2
Created a program for amstrongnumber in c
2 parents 0a62d39 + da5110c commit 0b746c8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

amstrongnumber.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
check if it is Armstrong number or not #
2+
#include <stdio.h>
3+
#include <math.h>
4+
5+
int main() {
6+
int num, originalNum, remainder, n = 0;
7+
float result = 0.0;
8+
9+
// Input the number
10+
printf("Enter an integer: ");
11+
scanf("%d", &num);
12+
13+
originalNum = num;
14+
15+
// Find the number of digits
16+
while (originalNum != 0) {
17+
originalNum /= 10;
18+
++n;
19+
}
20+
21+
originalNum = num;
22+
23+
// Calculate the sum of powers of digits
24+
while (originalNum != 0) {
25+
remainder = originalNum % 10;
26+
result += pow(remainder, n);
27+
originalNum /= 10;
28+
}
29+
30+
// Check if the number is an Armstrong number
31+
if ((int)result == num)
32+
printf("%d is an Armstrong number.\n", num);
33+
else
34+
printf("%d is not an Armstrong number.\n", num);
35+
36+
return 0;
37+
}

0 commit comments

Comments
 (0)