5-24 約分最簡分式 (15分)


#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <stdio.h>
using namespace std;

int main()
{
    int m,n;
    char c;
    scanf("%d%c%d",&m,&c,&n);
    int m1=m,n1=n;
    int a=1;
    if(m>n) swap(m,n);//使m成爲較小的一個數
    while(m!=0)
    {
        a=n%m;
        n=m;
        m=a;
    }
    printf("%d/%d\n",m1/n,n1/n);

    return 0;
}


發佈了73 篇原創文章 · 獲贊 25 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章