#1232: 求助


phenix (phenix)

學校 : 國立中正大學
編號 : 5092
來源 : [140.123.240.55]
最後登入時間 :
2009-02-21 22:15:17
a024. 最大公因數(GCD) | From: [218.169.86.100] | 發表日期 : 2009-01-22 22:40

以下是我的程式碼

#include<stdio.h>
int main ()
{
 long int a,b=1,r;
 
 while(b!=0)
 {          
scanf("%d %d",&a,&b);
  r=a%b;
  a=b;
  b=r;
 }
 printf("%d",a);
}

只要輸入12和5,他就不會輸出

 
#1235: Re:求助


morris1028 (碼畜)

學校 : 國立花蓮高級中學
編號 : 3529
來源 : [114.37.59.62]
最後登入時間 :
2021-07-12 19:00:43
a024. 最大公因數(GCD) | From: [118.161.223.181] | 發表日期 : 2009-01-22 23:32

以下是我的程式碼

#include
int main ()
{
 long int a,b=1,r; 
 scanf("%d %d",&a,&b);  /*寫程式時 要注意位置與順序*/

 while(b!=0)
 {           
  r=a%b;
  a=b;
  b=r;
 }
 printf("%d",a);
}

只要輸入12和5,他就不會輸出


 
#1285: Re:求助


phenix (phenix)

學校 : 國立中正大學
編號 : 5092
來源 : [140.123.240.55]
最後登入時間 :
2009-02-21 22:15:17
a024. 最大公因數(GCD) | From: [218.169.80.122] | 發表日期 : 2009-02-01 20:29

以下是我的程式碼

#include
int main ()
{
 long int a,b=1,r; 
 scanf("%d %d",&a,&b);  /*寫程式時 要注意位置與順序*/

 while(b!=0)
 {           
  r=a%b;
  a=b;
  b=r;
 }
 printf("%d",a);
}

只要輸入12和5,他就不會輸出

這樣得到的回覆是

編譯錯誤, 請檢查語法是否符合系統所支援的編譯器的要求。
錯誤訊息:
/tmp/code_129631.cpp:1:9: #include expects "FILENAME" or <FILENAME>
/tmp/code_129631.cpp: In function `int main()':
/tmp/code_129631.cpp:5: error: `scanf' undeclared (first use this function)
/tmp/code_129631.cpp:5: error: (Each undeclared identifier is reported only
   once for each function it appears in.)
/tmp/code_129631.cpp:12: error: `printf' undeclared (first use this function)

一開始我就那樣寫,但無法重複執行,只好修改在迴圈內,但就會無法映出

 
#1292: Re:求助


morris1028 (碼畜)

學校 : 國立花蓮高級中學
編號 : 3529
來源 : [114.37.59.62]
最後登入時間 :
2021-07-12 19:00:43
a024. 最大公因數(GCD) | From: [118.160.201.125] | 發表日期 : 2009-02-02 15:26

以下是我的程式碼

#include
int main ()
{
 long int a,b=1,r; 
 scanf("%d %d",&a,&b);  /*寫程式時 要注意位置與順序*/

 while(b!=0)
 {           
  r=a%b;
  a=b;
  b=r;
 }
 printf("%d",a);
}

只要輸入12和5,他就不會輸出

這樣得到的回覆是

編譯錯誤, 請檢查語法是否符合系統所支援的編譯器的要求。
錯誤訊息:
/tmp/code_129631.cpp:1:9: #include expects "FILENAME" or
/tmp/code_129631.cpp: In function `int main()':
/tmp/code_129631.cpp:5: error: `scanf' undeclared (first use this function)
/tmp/code_129631.cpp:5: error: (Each undeclared identifier is reported only
   once for each function it appears in.)
/tmp/code_129631.cpp:12: error: `printf' undeclared (first use this function)

一開始我就那樣寫,但無法重複執行,只好修改在迴圈內,但就會無法映出

抱歉忘記交你,修改成,應該是這樣吧?!

int main ()
{
 long int a,b=1,r; 
 while(scanf("%d %d",&a,&b)==2)  
  {
     while(b!=0)
    {           
     r=a%b;
     a=b;
     b=r;
    }
    printf("%d",a);
  }
 return 0; 
}

 
#1293: Re:求助


morris1028 (碼畜)

學校 : 國立花蓮高級中學
編號 : 3529
來源 : [114.37.59.62]
最後登入時間 :
2021-07-12 19:00:43
a024. 最大公因數(GCD) | From: [118.160.201.125] | 發表日期 : 2009-02-02 15:30

加上換行(\n)就AC了

 
#1306: Re:求助


chenaren ((′‧ω‧‵))

學校 : 國立臺灣大學
編號 : 3297
來源 : [140.112.30.122]
最後登入時間 :
2011-06-19 22:42:18
a024. 最大公因數(GCD) | From: [140.112.7.59] | 發表日期 : 2009-02-03 15:33

加上換行(\n)就AC了

 

 

 對啊

 
ZeroJudge Forum