Home >Backend Development >C#.Net Tutorial >How to input 3 numbers in C language and output the maximum value

How to input 3 numbers in C language and output the maximum value

青灯夜游
青灯夜游Original
2021-04-15 17:57:4070098browse

Method: First use scanf() to receive three numbers input from the keyboard; then use the "if else" statement to compare the sizes of the three numbers to obtain the maximum value; finally use the print() function to output the maximum value That’s it.

How to input 3 numbers in C language and output the maximum value

The operating environment of this tutorial: windows7 system, c99 version, Dell G3 computer.

c language input 3 numbers and output the maximum value

#include <stdio.h>
int main() {
    // 输入abc输出最大值
    int a;
    int b;
    int c;
    int max;
    scanf("%d %d %d", &a, &b, &c); // 输入请空格隔开最后回车
    /* if (a > b) {
        max = a;
    } else {
        max = b;
    } */
    max = a;
    if (b > max) {
        max = b;
    }
    if (c > max) {
        max = c;
    }
    printf("%d\n", max);
    return 0;    
}

Run:

How to input 3 numbers in C language and output the maximum value

Related recommendations:《C language video tutorial

The above is the detailed content of How to input 3 numbers in C language and output the maximum value. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn