How to output fraction instead of decimal number?

后端 未结 13 2064
余生分开走
余生分开走 2020-12-01 21:59

In C++, When I calculate 2/3, it will output decimal values, how can I just get the original format (i.e.g 2/3) instead of 0.66666667

Thanks

13条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 22:20

    #include 
    using namespace std;
    
    int main() {
        int a,b,q,r;
        cin>>a>>b;//first number and second number
        q = a/b;
        r = a-q*b;
        cout<

    I just got quotient by a/b then got the remainder by a-q*b. open for suggetions if any.

提交回复
热议问题