最简分数

发布时间 2023-08-01 09:32:34作者: 爱吃泡面的皮卡
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char** argv) {
    system("pause");
    double x,y;
    int c[1][10];
    int w;
    int k;
    do{
        cout<<"x=";
        cin>>x;
    }while(x>=1||x<=0);
    c[0][0]=1;//a
    y=x;
    while(fabs(y-(int)y)>1e-10){
        c[0][0]*=10;//a
        y=x*c[0][0];//a
    }
    c[0][1]=y;//b
    cout<<c[0][1]<<'/'<<c[0][0]<<endl;
    for(c[0][2]=c[0][1];c[0][2]>=1;c[0][2]--)//i
    if(c[0][1]%c[0][2]==0&&c[0][0]%c[0][2]==0){
        c[0][3]=c[0][2];
        break;
    }
    cout<<"最简分数为:";
    cout<<c[0][1]/c[0][3]<<'/'<<c[0][0]/c[0][3]<<endl;
    }