-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPassbyrefer.cpp
More file actions
47 lines (44 loc) · 895 Bytes
/
Copy pathPassbyrefer.cpp
File metadata and controls
47 lines (44 loc) · 895 Bytes
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
#include <stdio.h>
#include <math.h>
void FindArmstrongNumber(int &a, int &result)
{
int temp = a, sum = 0, digits = 0;
int num = a;
while (num != 0)
{
digits++;
num /= 10;
}
temp = a;
while (temp > 0)
{
int digit = temp % 10; // Get the last digit
sum += pow(digit, digits); // Raise it to the power of the number of digits and add to sum
temp /= 10; // Remove the last digit
}
if (sum == a)
{
result = 1; // 1 for Yes
}
else
{
result = 2; // 2 for No
}
}
int main()
{
int number;
int result;
printf("Enter your number\n");
scanf("%d", &number);
FindArmstrongNumber(number, result);
if (result == 1)
{
printf("ArmStrong number\n");
}
else
{
printf("Not an ArmStrong number\n");
}
return 0;
}