Table of Contents
问题
分数比较:比较两个分数的大小
分析
采用简化的模拟通分的过程: 第一个分数的分子乘以第二个分数的分母的结果与第一个分数的分母乘以第二个分数的分子结果比较。
程序
1: /** 2: * @file 043c.c 3: * @author Chaolong Zhang4: * @date Mon Jul 1 15:32:39 2013 5: * 6: * @brief 分数比较:比较两个分数的大小 7: * 8: */ 9: 10: #include 11: 12: 13: int main(int argc, char *argv[])14: {15: int numerator1,numerator2,denominator1,denominator2;16: 17: printf ("please input the two fraction\n");18: scanf( "%d/%d;%d/%d", &numerator1,&denominator1,&numerator2,&denominator2);19: if (numerator1*denominator2 >= numerator2*denominator1)20: {21: printf ("%d/%d >= %d/%d\n",numerator1,denominator1,numerator2,denominator2);22: }23: else {24: printf ("%d/%d < %d/%d\n",numerator1,denominator1,numerator2,denominator2);25: }26: return 0;27: }
输出
please input the two fraction2/3;3/42/3 < 3/4