File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments