千寻0 发表于 2014-7-14 13:11:32

初学者求别的写法

这个有没有别的写法
#include<stdio.h>
#include <math.h>
void main()
{
      int x;
      x=0;
loop:if(sqrt(x+100)==(int)sqrt(x+100)&&sqrt(x+168)==(int)sqrt(x+168))
      {
                printf("%d\n",x);
      }
      else
      {
                x++;
                goto loop;
      }
      
}

♂我是上帝♂ 发表于 2014-7-14 13:11:33

#include <stdio.h>
#include <math.h>

void main(){
        int x = 0;
        while(sqrt(x + 100) != (int)sqrt(x + 100) || sqrt(x + 168) != (int)sqrt(x + 168)){
                x++;
        }
        printf("%d\n",x);
}

avril270 发表于 2014-7-14 14:00:03

为什么要用goto啊,用while不就好了吗?
页: [1]
查看完整版本: 初学者求别的写法