Visual C++ 基礎篇 一維陣列相加後求最大值

a[4]={4,9,7,3}
b[4]={5,2,3,9}
將兩個一維陣列相加後,求其最大值??

蓋棉被 talk543.tw p28.png

 
程式碼
#include <iostream>
using namespace std;

void main()
{
int a[4] = { 4,9,7,3 }, b[4] = { 5,2,3,9 }, i, j, s[4], max = s[0];

for (i = 0; i <= 3; i++)
{
s[i] = a[i] + b[i];//放入S陣列
cout << s[i] << " " ;//將 S陣列秀出
}
cout << endl;
for (j = 0; j <= 3; j++) {
cout << "秀出第" << j + 1 << "次的數值:" << s[j] << endl;
if (s[j] > max) {
max = s[j];
}
}
cout << "最大值:" << max << endl;
system("Pause");
}[/i][/i][/i][/i]

[i][i][i] [/i][/i][/i]
已邀請:

要回復主題請先登入註冊