读书人

简单有关问题,错哪了

发布时间: 2012-02-22 19:36:56 作者: rapoo

简单问题,哪里错了?
#include <math.h>
#include <stdio.h>
main()
{
double x,y,z;
int n;

printf( "input a integer:\n ",&n);
scanf( "%d ",&n);

// x=3,y=4;
if // (x*x+y*y==z*z && x <=y && z <=n)
(pow(x,2)+ pow(y,2) == pow(z,2) && x <y && z <=n)
{

for (x=3;;x=x++)
{
for (y=4;;y=y++)
{

printf( "output :\n ");
printf( "%d%d%d ",x,y,z);
}
}
}
}


我这个程序是哪里里错了.输入一个整数n,所有勾股定理成立的,x平方+y平方=z平方.z小于n的全部罗列的程序.请指教.

[解决办法]
#include <math.h>
#include <stdio.h>
void main()
{
int x,y,z;
int n;

printf( "input a integer:\n ",n);
scanf( "%d ",&n);





for (x=1;x <n;x++)
for (y=1;y <n;y++)
for (z=1;z <=n;z++)
{

if((pow(x,2)+ pow(y,2) == pow(z,2) )&&( x <y))
{
printf( "output :\n ");
printf( "%d %d %d\n ",x,y,z);
}
}


}

[解决办法]
#include <math.h>
#include <stdio.h>
#define FALSE 0
#define TRUE 1
#define TRAI(x,y,z) ((((x*x) + (y*y) == (z*z)) && (x > 0) && (y > 0))? TRUE : FALSE)
main()
{
int x,y,z;
int n;

printf( "input a integer:\n ");
scanf( "%d ",&n);

for(x = 0; x <= n; x++)
{
for(y = 0; y <= n; y++)
{

for(z = 0; z <= n; z++)
{
if(TRAI(x,y,z))
{
printf( "output :\n ");
printf( "%d %d %d\n ",x,y,z);
}
}
}
}
}

读书人网 >C语言

热点推荐