任意输入10个数 求其中最大值 这个能不能用while或者do…while编程(只有一个scanf)?

#include<stdio.h>
main()
{int i,x,s;
printf("输入10个数");
scanf("%d",&x);
s=x;
for(i=1;i<=9;i++)
{scanf("%d",&x);
if(x>s)
s=x;

printf("%d",s);
getch();
}

for和while本质上是同一个逻辑,你把变量声明拿到外面,然后终止条件作为while的终止条件即可
代码示例如下
有帮助望采纳~

#include <stdio.h>

int main(int argc, char const *argv[])
{
    int i = 0;
    int x, max = 0;
    while (i < 10)
    {
        scanf("%d", &x);
        if (i == 0)
        {
            max = x;
        }
        else
        {
            max = max > x ? max : x;
        }
    }
    printf("%d",max);
};
#include <stdio.h>
int main()
{
    int i = 0, n, max = 0;
    while (i < 10)
    {
        scanf("%d", &n);
        if (i == 0 || n > max)
            max = n;
        i++;
    }
    printf("%d",max);
};

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632