首页 > 其他 > 详细

结构-01. 有理数比较

时间:2014-08-26 00:13:35      阅读:308      评论:0      收藏:0      [点我收藏+]
 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. 有理数比较

原文:http://www.cnblogs.com/boomkeeper/p/F1.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!