为了账号安全,请及时绑定邮箱和手机立即绑定

C语言编程题 分数比较

C语言编程题 分数比较

C++
qq_西了个瓜_1 2018-05-29 15:52:43
利用人工方式比较分数大小的最常见的方法是:对分数进行通分后比较分子的大小。请编程模拟手工比较两个分数的大小。首先输入两个分数分子分母的值,例如"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"
查看完整描述

2 回答

?
灯初上夜未央

TA贡献2条经验 获得超1个赞

#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语言实现

查看完整回答
1 反对 回复 2018-05-29
?
清峯

TA贡献2条经验 获得超1个赞

#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;
}

查看完整回答
1 反对 回复 2018-05-29
  • 2 回答
  • 0 关注
  • 5709 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信