溫馨提示×

c語言怎么判斷三個數(shù)的大小

小億
161
2024-03-01 13:12:15
欄目: 編程語言

可以通過比較三個數(shù)之間的大小關(guān)系來判斷它們的大小。以下是一個示例代碼:

#include <stdio.h>

int main() {
    int num1, num2, num3;

    printf("Enter three numbers: ");
    scanf("%d %d %d", &num1, &num2, &num3);

    if (num1 >= num2 && num1 >= num3) {
        printf("%d is the largest number\n", num1);
    } else if (num2 >= num1 && num2 >= num3) {
        printf("%d is the largest number\n", num2);
    } else {
        printf("%d is the largest number\n", num3);
    }

    return 0;
}

在上面的示例中,首先從用戶那里獲取三個數(shù)字,然后通過比較它們之間的大小關(guān)系來確定哪一個是最大的。這個示例只是一個簡單的方法,有多種其他方法可以用來判斷三個數(shù)的大小。

0