鱼C论坛

 找回密码
 立即注册
查看: 3373|回复: 1

cyy

[复制链接]
发表于 2023-11-11 11:11:52 | 显示全部楼层 |阅读模式
本帖为密码帖 ,请输入密码 
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-11-11 11:11:59 | 显示全部楼层
  1. #include <stdio.h>

  2. int main() {
  3.     int n, max1 = 0, max2 = 0;
  4.     scanf("%d", &n);
  5.     for (int i = 1; i <= n; i++) {
  6.         int num;
  7.         scanf("%d", &num);
  8.         if (i % 2 == 1) {
  9.             max1 = max1 > num ? max1 : num;
  10.         } else if (i % 2 == 0) {
  11.             max2 = max2 > num ? max2 : num;
  12.         }
  13.     }
  14.     if (max1 > max2) {
  15.         printf("Greater than");
  16.     } else if (max2 > max1) {
  17.         printf("Less than");
  18.     } else if (max2 == max1) {
  19.         printf("Equal");
  20.     }
  21.     return 0;
  22. }
复制代码


这段代码的作用是接受输入的卡片数字,然后比较奇数位置和偶数位置的数字,找出最大值并进行比较。如果奇数位置的最大值大于偶数位置的最大值,则输出"Greater than";如果偶数位置的最大值大于奇数位置的最大值,则输出"Less than";如果两者相等,则输出"Equal"。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-22 09:54

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表