-
Notifications
You must be signed in to change notification settings - Fork 0
/
nestedloop8.c
45 lines (41 loc) · 892 Bytes
/
nestedloop8.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
//To find the nth armstrong number
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int n, count=1;
printf("Enter number: ");
scanf("%d", &n);
if (n>31)
{
printf("Please enter a number less than or equal to 31");
exit(1);
}
for (int i=1;i<=1000000000;i++)
{
int num=i, rem, sum=0;
//count number of digits
int digit= (int) log10(num)+1;
while(num>0)
{
//find sum
rem=num%10;
sum=sum+pow(rem,digit);
num=num/10;
}
//check for armstrong number
if(i==sum)
{
if(count==n)
{
printf("%d\n",i);
break;
}
else
{
count++;
}
}
}
}