-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion_2.c
More file actions
56 lines (46 loc) · 1.08 KB
/
question_2.c
File metadata and controls
56 lines (46 loc) · 1.08 KB
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
50
51
52
53
54
55
56
/*
* C program to print all Armstrong numbers between a given range
*/
#include <stdio.h>
int isArmstrong(int num);
void printArmstrong(int start, int end);
int main()
{
int start, end;
printf("Hello!\nI can help you find strong numbers between an interval of two integer numbers!\n");
printf("Enter lower limit to print armstrong numbers: ");
scanf("%d", &start);
printf("Enter upper limit to print armstrong numbers: ");
scanf("%d", &end);
printf("All armstrong numbers between %d to %d are: \n", start, end);
printArmstrong(start, end);
return 0;
}
int isArmstrong(int num)
{
int temp, lastDigit, sum;
temp = num;
sum = 0;
while(temp != 0)
{
lastDigit = temp % 10;
sum += lastDigit * lastDigit * lastDigit;
temp /= 10;
}
if(num == sum)
return 1;
else
return 0;
}
void printArmstrong(int start, int end)
{
while(start <= end)
{
if(isArmstrong(start))
{
printf("%d\n", start);
}
start++;
}
printf("\n");
}