C语言编程题 分数比较

利用人工方式比较分数大小的最常见的方法是:对分数进行通分后比较分子的大小。请编程模拟手工比较两个分数的大小。首先输入两个分数分子分母的值,例如"11/13,17/19",比较分数大小后输出相应的提示信息。例如,第一个分数11/13小于第二个分数17/19,则输出"11/13<17/19"。


程序的运行结果示例1:

Input a/b, c/d:11/13,17/19↙

11/13<17/19

程序的运行结果示例2:

Input a/b, c/d:17/19,23/27↙

17/19>23/27

程序的运行结果示例3:

Input a/b, c/d:3/4,18/24↙

3/4=18/24


输入提示信息:"Input a/b, c/d:"  (注意:逗号后面有一个空格)

输入格式: "%d/%d,%d/%d"

输出格式:

比较的结果是大于:"%d/%d>%d/%d\n"

比较的结果是小于:"%d/%d<%d/%d\n"

比较的结果是相等:"%d/%d=%d/%d\n"


qq_西了个瓜_1
浏览 5710回答 2
2回答

灯初上夜未央

#include<stdio.h> int main() {     int a, b, c, d;     printf("Input a/b, c/d:");     scanf("%d/%d,%d/%d", &a, &b, &c, &d);     if(a*d < c*b)     {         printf("%d/%d<%d/%d\n",a,b,c,d);     }     if(a*d > c*b)     {         printf("%d/%d>%d/%d\n",a,b,c,d);     }     if(a*d == c*b)     {         printf("%d/%d=%d/%d\n",a,b,c,d);     }     return 0; }c语言实现

清峯

#include <iostream>#include <stdlib.h>using namespace std;template <class T>int find(T a, T b){ double team; team = a / b; return team;}int main(){ double a1 , b1, c , d; cout << "输入两个数 以空格为间隔" << endl; cin >> a1 >> b1; cout << "再次输入两个数" << endl; cin >> c >> d; if (find(a1, b1) == find(c, d)) { cout <<"比较的结果:"<< a1 << "/" << b1 << " = " << c << "/" << d << endl; } if (find(a1, b1) > find(c, d)) { cout << "比较的结果:" << a1 << "/" << b1 << " > " << c << "/" << d << endl; } if (find(a1, b1) < find(c, d)) { cout << "比较的结果:" << a1 << "/" << b1 << " < " << c << "/" << d << endl; } system("pause"); return 0;}
打开App,查看更多内容
随时随地看视频慕课网APP