首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

很简单的有关问题,高手看一下

2012-03-25 
很简单的问题,高手看一下.#includemath.h#includestdio.hmain(){intx,y,z,nprintf( inputainteger:\

很简单的问题,高手看一下.
#include   <math.h>
#include   <stdio.h>
main(){
int   x,y,z,n;

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

for   (x=3;;x=x+1)
for   (y=4;;y=y+1)
for   (z=5;;z=z+1)
{  
if   (x*x+y*y!=z*z)   break;
        }    

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


没有结果.不知道怎么错了.高手看一下.
还有;就这个问题.什么是的程序运行时间微秒单位的输出,如果n=10,100,1000等等

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

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

for (x=3;;x=x+1)
{
for (y=4;;y=y+1)
{
for (z=5;;z=z+1)
{
if (x*x+y*y!=z*z) break;
}
break;
}
break;
}

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

这么就有了,注意break只跳出当前循环!
[解决办法]
#include <math.h>
#include <stdio.h>
main(){
int x,y,z,n;

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

for (x=3;;x=x+1)
{
for (y=4;;y=y+1)
{
for (z=5;;z=z+1)
{
if (x*x+y*y!=z*z)
{
if ( (x <=y) && (z <=n) )
{
printf( "output integer:\n ");
printf( "%d%d%d ",x,y,z);
}
return;
}
}
}
}

}
直接用return吧,减少代码量和出错的机会!

热点排行