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

Join the forum, it's quick and easy

AndreiL
Welcome to AndreiL.
Enjoy your time.
Please log in.
AndreiL
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Armstrong number finder

Go down

Armstrong number finder Empty Armstrong number finder

Post by Lucaci Andrei 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 : 28
Location : Cluj-Napoca

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