21xrx.com
2025-04-21 16:32:04 Monday
文章检索 我的文章 写文章
C语言编程-输出三个整数的最大值
2023-06-16 10:45:44 深夜i     32     0
C语言 整数 最大值

在C语言编程中,经常需要找到一组整数中的最大值。本文将介绍一种简单的方法,可以在给定三个整数的情况下,输出其最大值。

首先,我们可以使用scanf函数从用户输入中获取三个整数,分别存储在变量a、b、c中。然后,我们可以使用if语句来比较这三个数的大小,找到最大值并输出。

代码实现如下:

#include 
int main() {
  int a, b, c, max;
  printf("请输入三个整数:");
  scanf("%d %d %d", &a, &b, &c);
  if (a >= b && a >= c)
    max = a;
  
  else if (b >= a && b >= c)
    max = b;
  
  else
    max = c;
  
  printf("最大值为:%d", max);
  return 0;
}

  
  

评论区

请求出错了