dayglow 2021-08-26 10:26 采纳率: 33.3%
浏览 115
已结题

c++中用compare函数比较两个数大小

img
如题,是老师给的作业,但写出来总有错。帮忙看看
#include
using namespace std;

// 请在此编写compare()函数

//~

void PrintLine(const char* s) {
cout<< s << endl;
}

void main() {
int x, y;
PrintLine("Input X:");
cin>>x;
PrintLine("Input Y:");
cin>>y;

int result = 0;
//result = compare(x, y);
if (result == 0) {
    PrintLine("X is equal to Y.");
} else if (result < 0) {
    PrintLine("X is less than Y.");
} else {
    PrintLine("X is greater than Y.");
}

}

  • 写回答

3条回答 默认 最新

  • 诺er~ 2021-08-26 10:28
    关注
    
    int compare(int a,int b)
    {
        if(a<b) return -1;
        if(a>b) return 1;
        else return 0;
    }
    
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 8月26日
  • 修改了问题 8月26日
  • 创建了问题 8月26日

悬赏问题

  • ¥50 rk3588板端推理
  • ¥50 opencv怎么去掉 数字0中间的斜杠。
  • ¥15 这种情况的伯德图和奈奎斯特曲线怎么分析?
  • ¥50 paddleocr带斜线的0很容易识别成9
  • ¥15 电子档案元素采集(tiff及PDF扫描图片)
  • ¥15 flink-sql-connector-rabbitmq使用
  • ¥15 zynq7015,PCIE读写延时偏大
  • ¥15 使用spss做psm(倾向性评分匹配)遇到问题
  • ¥20 vue+UEditor附件上传问题
  • ¥15 想做个WPS的自动化代码,不知道能做的起不。