程序那里出错了——水仙花

来源:百度知道 编辑:UC知道 时间:2024/06/19 19:46:44
#include<iostream.h>
#include<math.h>
void main()
{int m;
for(m=100;m<=999;m++)
m==((m%10)*(m%10)*(m%10)+(m/10%10)*(m/10%10)(m/10%10)+(m/100)*(m/100)*(m/100));

cout<<m<<endl;

}
看见你发了这么多,我都不好意思不选你了,但是你的第一程序void main()
{
int ge,shi,bai,number;

for(number=100;number<1000;number++) 比如改为这个
//"水仙花数"实现代码
#include<iostream.h>

void main()
{
int ge,shi,bai,number;

for(number=100;number<1000;number++)
{
bai=number/100;
shi=(number%100)/10;
ge=number%10;
if(number==bai*bai*bai+shi*shi*shi+ge*ge*ge) ;
cout<<"number="<<number<<endl;

}

} 在VC++里运行,就有问题了
{
bai=number/100;
shi=(number%100)/10;
ge=number%10;
if(number==bai*bai*bai+shi*shi*shi+ge*ge*ge) printf("\nnumber=%d\n",number

C语言的"水仙花数"实现代码:

void main()
{
int ge,shi,bai,number;

for(number=100;number<1000;number++)
{
bai=number/100;
shi=(number%100)/10;
ge=number%10;
if(number==bai*bai*bai+shi*shi*shi+ge*ge*ge) printf("\nnumber=%d\n",number);
}
getch();
}

Visual Basic的"水仙花数"实现代码:

Private Sub Form_Click()
Dim a, b, c As Integer 'a(个)b(十)c(百)

For a = 0 To 9
For b = 0 To 9
For c = 1 To 9
If a ^ 3 + b ^ 3 + c ^ 3 = a + 10 * b + 100 * c Then
MsgBox 100 * c + 10 * b + a
End If
Next c
Next b
Next a

End Sub

FORTRAN的"水仙花数"实现代码:

WRITE(*,30)

DO 10 K=100,999

IA=K/100

IB=MOD(K,100)/10

IC=MOD(K,10)

IF(K.NE.IA**3+IB**3+IC**3) GOTO 10
<