首页 > 代码库 > 结构-01. 有理数比较

结构-01. 有理数比较

 1 /* 2  * Main.c 3  * F1-结构-01. 有理数比较 4  *  Created on: 2014年8月25日 5  *      Author: Boomkeeper 6  *******测试通过********* 7  */ 8  9 #include <stdio.h>10 11 int main(void) {12 13     struct rationalNumber {14         int numerator;15         int denominator;16     } num1, num2;//要比较的两个有理数变量17 18     int numerator1, denominator1, numerator2, denominator2;//分别对应:分子/分母    分子/分母19     scanf("%d/%d %d/%d", &numerator1, &denominator1, &numerator2, &denominator2);20 21     num1.numerator = numerator1;22     num1.denominator = denominator1;23     num2.numerator = numerator2;24     num2.denominator = denominator2;25 26     //通分27     num1.denominator *= denominator2;28     num1.numerator *= denominator2;29 30     num2.denominator *= denominator1;31     num2.numerator *= denominator1;32 33     //输出结果34     if (num1.numerator > num2.numerator)35         printf("%d/%d > %d/%d\n", numerator1, denominator1, numerator2, denominator2);36     else if (num1.numerator < num2.numerator)37         printf("%d/%d < %d/%d\n", numerator1, denominator1, numerator2, denominator2);38     else if (num1.numerator == num2.numerator)39         printf("%d/%d = %d/%d\n", numerator1, denominator1, numerator2, denominator2);40 41     return 0;42 }

 

题目链接:

http://pat.zju.edu.cn/contests/basic-programming/%E7%BB%93%E6%9E%84-01

 

 

.

结构-01. 有理数比较