用c语言写一个十个数求最大值
时间: 2023-05-15 15:05:08 浏览: 73
可以使用以下代码来实现:
#include <stdio.h>
int main() {
int nums[10];
int max = 0;
printf("请输入10个整数:\n");
for (int i = 0; i < 10; i++) {
scanf("%d", &nums[i]);
if (nums[i] > max) {
max = nums[i];
}
}
printf("最大值为:%d\n", max);
return 0;
}
相关问题
用c语言写一个三个数求最大值
好的,以下是用 C 语言写的一个求三个数最大值的示例代码:
```c
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:\n");
scanf("%d %d %d", &a, &b, &c);
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
printf("三个数中最大的数是:%d\n", max);
return 0;
}
```
这个程序首先通过 `scanf` 函数读入三个整数,然后使用 `if` 语句和一个 `max` 变量找出这三个数中的最大值,并输出结果。
用C语言写一个多个数求最大值
的程序
#include <stdio.h>
int main()
{
int num, max, i;
printf("请输入要比较的数的个数:");
scanf("%d", &num);
printf("请输入第一个数:");
scanf("%d", &max);
for (i = 1; i < num; i++)
{
int temp;
printf("请输入第%d个数:", i + 1);
scanf("%d", &temp);
if (temp > max)
{
max = temp;
}
}
printf("最大值为:%d\n", max);
return 0;
}
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)