Reading fractions in C

后端 未结 6 482
臣服心动
臣服心动 2021-01-14 23:45

How do I read a fraction into C to do math with it? (The fraction will contain the slash symbol) For example, A user will input 3/12. (a string) The program will find the gc

6条回答
  •  囚心锁ツ
    2021-01-15 00:36

    #include 
    
    typedef struct
    {
    int num, denom;
    }fraction;
    
    int main()
    {
    fraction fract = {1,2};
    
    printf("fraction: %i/%i", fract.num, fract.denom);
    return 0;
    }
    

提交回复
热议问题