回文章列表
作者one.bbs@sparc20.ee.cycu.edu.tw (不知如何是好??), 信區: sources
標題Re: 可不可以幫幫我thx!1
時間中原電機站 (Mon Oct 18 22:34:52 2004)
轉信站: GIBBS!news2.ncku!ctu-gate!news.nctu!news.ntu!news.mcu!news.csie.mcu!new
Origin: sparc20.ee.cycu.edu.tw

※ 引述《Edoll@kkcity.com.tw (永遠)》之銘言:
: 各位高手幫幫我這個菜鳥吧!!!
: 題目是找出最大公因數
: #include<stdlib.h>
: int x,y;
: main(void)
: {
:     printf("請輸入兩個整數",x,y);
:     scanf("%d",&x);
:     scanf("%d",&y);
:     if(y>x)
:      do{
:      x=y%x;
:      abs(y)/abs(x);
:  }
:       while(abs(y) % abs(x) != 0);
:     printf("最大公因數為%d",abs(x));
:     if(x>y)
:     do{
:      y=x%y;
:      abs(y)/abs(x);
:  }
:       while(abs(x) % abs(y) != 0);
:     printf("最大公因數為%d",abs(x));
:      system("PAUSE");
:      return(0);
: }
: 要怎樣修正呢??
: 感激不盡!!!
#include<stdlib.h>
int x,y;
main(void)
{
    printf("請輸入兩個整數");//,x,y);
    scanf("%d",&x);
    scanf("%d",&y);
    if(y>x)
    {
     do{
         if(y%x==0) break;  //如果y是x的倍數,則最大公因數就是x
                           //所以可以不用再跑回圈,break跳出回圈
        x=y%x;
       }while(abs(y) % abs(x) != 0);
    printf("最大公因數為%d\n",abs(x));
    }

    else
    {
        do{
           if(x%y==0) break; //如果x是y的倍數,則最大公因數就是y
                             //所以可以不用再跑回圈,break跳出回圈
           y=x%y;
           //abs(y)/abs(x);
           }while(abs(x) % abs(y) != 0);
           printf("最大公因數為%d\n",abs(y));
     }
     system("PAUSE");
     return(0);
}

--
                    ..  ˊ                            
       ▋ ̄ .˙
        ▌ ̄中原電機心站 CYEE     ﹉    ﹊◥◤
     ============================================================
                                                  From:  220.138.56.127--
Origin: 中原電機心站 bbs.ee.cycu.edu.tw (140.135.12.1)
文章選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻