PDA

View Full Version : Số Amstrong



LieuKyThien
21-07-2009, 10:43 AM
Yêu cầu bài toán: tìm các số Amstrong nhỏ hơn 100.
VD: 153 là số Amstrong vì 1^3 + 5^3 + 3^3 = 153

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,d,c,t;
printf("So Amstrong nho hon 1000 gom:");
for(i=100;i<=999;i++)
{
d=i%10;
t=i/100;
c=i/10%10;
if(d*d*d+c*c*c+t*t*t==i)
printf(" %d",i);
}
getch();
}