小编Meg*_*EXE的帖子

最大和最小的四个整数(没有数组,没有函数,最少'if'语句)

你看,我自学了C++(不完全,我还在拖延-_-).所以,现在我开始上大学,他们正在教C,他们让我们做了一个输入四个整数的程序,我们必须告诉它们中最大和最小的.简单,不是吗?

问题是,我已经对函数和数组有了很好的理解.是的,我可以在阵列中编程,没问题.但由于这是第一个实验室,我们还没有"学到"那个,所以我不能使用其中的任何一个,它就会非常简单.

这就是我在那里写的(某种程度上感觉不对).

#include<stdio.h>

int main(void)
{
    int first, second, third, fourth;
    printf("Enter four integers (separated by space): ");
    scanf("%d %d %d %d", &first, &second, &third, &fourth);

    if((first>second) && (first>third) && (first>fourth))
        printf("\nFirst number is largest");
    else if((second>first) && (second>third) && (second>fourth))
        printf("\nSecond number is largest");
    else if((third>second) && (third>first) && (third>fourth))
        printf("\nThird number is largest");
    else if((fourth>second) && (fourth>third) && (fourth>first))
        printf("\nFourth number is largest");

    if((first<second) && (first<third) && (first<fourth))
        printf("\nFirst number is smallest");
    else if((second<first) && (second<third) && …
Run Code Online (Sandbox Code Playgroud)

c

16
推荐指数
5
解决办法
7万
查看次数

标签 统计

c ×1