AndreiL
Welcome to AndreiL.
Enjoy your time.
Please log in.

Armstrong number finder

Go down

Armstrong number finder Empty Armstrong number finder

Post by Lucaci Andrei on Thu Jan 24, 2013 4:34 am

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <math.h>
int main(){
int i;
for (i=1;i<9999999;i++){
int temp = i, len = (int)log10(i)+1, rez=0, j=0;
int a[len];
for (;j<len;j++){
a[j] = temp%10;
temp/=10;
}
for (;j--;) rez+=pow(a[j], len);
if (rez==i) printf("%d\n", rez);
}
return 0;
}

Lucaci Andrei
Lucaci Andrei
"Tata Lor"
Armstrong number finder 138

Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 26
Location : Cluj-Napoca

View user profile http://www.andreil.wgz.ro

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum