Using C language to compare the size of two fractions __c language

Source: Internet
Author: User
/* ************************************************************************** * File NAME:12.CMPFRAC.C score Fractions Molecular numerator denominator denominator * function:1) * 2 * author:xubing * Created time:2016 year September 29 Thursday 09:03 45 SEC ************************************************************************** * * #include <stdio.h> #define
    Fracsize 2 #define NUME 0 #define Deno 1 int cmpfrac (int *frac1, int *frac2) {int temp_frac1[fracsize];

int temp_frac2[fracsize];  /******************** two fractions for Tong *********************/temp_frac1[nume] = frac1[nume] * Frac2[deno]; Numerator of the first fraction =/molecule of the first fraction * The denominator of the second fraction temp_frac2[nume] = frac2[nume] * frac1[d  ENO]; Numerator of the second fraction =/molecule of the second fraction * The denominator of the first fraction if (Temp_frac1[nume] > Temp_frac2[num
    E]) {return 1;
    } if (temp_frac1[nume] = = Temp_frac2[nume]) {return 0;
} return-1; int main () {int frac_num1[fracsize];
    int frac_num2[fracsize];

    int flag;
    printf ("Please input one fraction (format:n/m): \ n");
    scanf ("%d/%d", &frac_num1[0],&frac_num1[1]);
    GetChar ();
    printf ("Please input another fraction (format:n/m): \ n");
    scanf ("%d/%d", &frac_num2[0],&frac_num2[1]);

    GetChar ();
    Flag = Cmpfrac (FRAC_NUM1, frac_num2);
    printf ("The result is:\n"); Switch (flag) {Case 1: {printf ("%d/%d >%d/%d\n", frac_num1[0],frac_num1[1],frac_num2[0
            ],FRAC_NUM2[1]);
        Break
            Case 0: {printf ("%d/%d =%d/%d\n", frac_num1[0],frac_num1[1],frac_num2[0],frac_num2[1]);
        Break 
            } case-1: {printf ("%d/%d <%d/%d\n", frac_num1[0],frac_num1[1],frac_num2[0],frac_num2[1]);
        Break
            } default: {printf ("error\n");
        Break

} return 0;
 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.