使用C++程序编写5 个浮点数,求平均值后输出
源代码如下:
#include <iostream>using namespace std;int main()
{float arr[5]={7,10,3,9,8};int i;float sum = 0;float avg = 0;for(i=0;i<5;i++){sum =sum +arr[i];}avg = sum/5;cout << "平均值是:" << avg << endl;return 0;
}
程序编译结果如下:
源代码如下:
#include <iostream>using namespace std;int main()
{float arr[5]={7,10,3,9,8};int i;float sum = 0;float avg = 0;for(i=0;i<5;i++){sum =sum +arr[i];}avg = sum/5;cout << "平均值是:" << avg << endl;return 0;
}
程序编译结果如下: