mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4mobile wallpaper 5mobile wallpaper 6mobile wallpaper 7
38 字
1 分钟
一维数组的输入输出
2026-05-28

题目描述#

输入10个整数到一维数组中,计算非负数的和,并找出最大值和最小值。

代码#

#include <stdio.h>
#define N 10
int main()
{
int a[N] = { 0 }, sum = 0, max = 0, min = 0;
for (int i = 0;i < N;i++)
{
scanf("%d", &a[i]);
if (i == 0)
{
max = a[i];
min = a[i];
}
if (a[i] >= 0)
{
sum += a[i];
if (a[i] > max)
{
max = a[i];
}
if (a[i] < min)
{
min = a[i];
}
}
}
printf("sum=%d\nmax=%d\nmin=%d", sum, max, min);
}
分享

如果这篇文章对你有帮助,欢迎分享给更多人!

一维数组的输入输出
https://blog.sherry.qzz.io/posts/c/一维数组的输入输出/
作者
Sherry
发布于
2026-05-28
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

目录