从键盘输入不超过50个非负整数,当输入为负值时,表示输入结束。试编程求出其中的最大值。 输入格式: 在一行中给出不超过50个非负整数(空格分隔),以负数结束。c语言
时间: 2023-08-21 14:04:59 浏览: 1018
以下是使用C语言编写的程序,可以实现输入不超过50个非负整数,并求出其中的最大值:
```c
#include <stdio.h>
int main()
{
int num, max = 0;
scanf("%d", &num);
while (num >= 0)
{
if (num > max)
{
max = num;
}
scanf("%d", &num);
}
printf("The maximum number is %d\n", max);
return 0;
}
```
程序首先读取第一个整数,然后使用while循环来读取后续的非负整数。在循环中,如果读取到的数字比当前最大值大,则更新最大值。当读取到负数时,循环结束并输出最大值。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)