以下是比较三个整数大小的C语言程序:

#include <stdio.h>

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

程序先要求用户输入三个整数,然后通过if和else if语句进行比较,最后输出最大的那个数。如果要比较最小的数,只需将大于号改为小于号即可。

C语言比较三个整数大小:代码示例与解释

原文地址: http://www.cveoy.top/t/topic/miRj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录