从键盘输入n个整数,求平均值和最小值
答案:3 悬赏:40 手机版
解决时间 2021-02-19 16:55
- 提问者网友:你挡着我发光了
- 2021-02-19 07:04
从键盘输入n个整数,求平均值和最小值
最佳答案
- 五星知识达人网友:山河有幸埋战骨
- 2021-02-19 07:37
#include
void main()
{
int n = 0, i = 0;
int a[100] = {0};
int sum = 0, min = 0;
printf("你要输入多少个数?");
scanf("%d",&n);
getchar();
for(i = 0; i < n; i++)
{
printf("请输入第%d个数:", i+1);
scanf("%d",&a[i]);
sum += a[i];
if(a[i] <= a[0])
{
min = a[i];
a[0] = min;
}
}
printf("您输入的 %d 个数中,最小的是 %d ,平均值为:%f",n,min,sum*1.0/n);
}
追问有错误啊。。。哥们
void main()
{
int n = 0, i = 0;
int a[100] = {0};
int sum = 0, min = 0;
printf("你要输入多少个数?");
scanf("%d",&n);
getchar();
for(i = 0; i < n; i++)
{
printf("请输入第%d个数:", i+1);
scanf("%d",&a[i]);
sum += a[i];
if(a[i] <= a[0])
{
min = a[i];
a[0] = min;
}
}
printf("您输入的 %d 个数中,最小的是 %d ,平均值为:%f",n,min,sum*1.0/n);
}
追问有错误啊。。。哥们
全部回答
- 1楼网友:未来江山和你
- 2021-02-19 09:24
#include
int main(void)
{
int n = 4;
int total = 0;
int min = 0x80000000-1;
int i = 0;
int val = 0;
for (i = 0; i < n; i++) {
scanf("%d", &val);
if(val min = val;
total += val;
}
printf("最小数%d 平均值%.2f ", min, total/(float)i);
return 0;
}追问谢谢,但好像不行啊
int main(void)
{
int n = 4;
int total = 0;
int min = 0x80000000-1;
int i = 0;
int val = 0;
for (i = 0; i < n; i++) {
scanf("%d", &val);
if(val
total += val;
}
printf("最小数%d 平均值%.2f ", min, total/(float)i);
return 0;
}追问谢谢,但好像不行啊
- 2楼网友:你哪知我潦倒为你
- 2021-02-19 07:50
#include
#include
#include
int main()
{
float average = 0;
int count = 0;
int number = 0;
int sum = 0;
int min = INT_MAX;
while(scanf("%d",&number)!=EOF){
count++;
sum += number;
average = sum/count;
min = number printf("平均数:%f\n最小值:%d\n", average, min);
}
return 0;
}
#include
#include
int main()
{
float average = 0;
int count = 0;
int number = 0;
int sum = 0;
int min = INT_MAX;
while(scanf("%d",&number)!=EOF){
count++;
sum += number;
average = sum/count;
min = number
}
return 0;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯