C++,已知a数组int a[10]={1,2,3,4,5,6,7,8,9,10};,编写程序,求a数组中偶数的个数和偶数的平均值
C++,已知a数组inta[10]={1,2,3,4,5,6,7,8,9,10};,编写程序,求a数组中偶数的个数和偶数的平均值...
C++,已知a数组int a[10]={1,2,3,4,5,6,7,8,9,10};,编写程序,求a数组中偶数的个数和偶数的平均值
展开
2个回答
展开全部
#include <iostream>
using namespace std;
int main()
{
int i = 0;
int num = 0;
int avg = 0;
int a[] = { 1,2,3,4,5,6,7,8,9,10 };
for (i = 0; i < 10; i++)
{
if(a[i] % 2 == 0)
{
num++;
avg +=a[i];
}
}
avg /= num;
cout << "num:" << num << " avg: " << avg << endl;
return 0;
}
using namespace std;
int main()
{
int i = 0;
int num = 0;
int avg = 0;
int a[] = { 1,2,3,4,5,6,7,8,9,10 };
for (i = 0; i < 10; i++)
{
if(a[i] % 2 == 0)
{
num++;
avg +=a[i];
}
}
avg /= num;
cout << "num:" << num << " avg: " << avg << endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询