標題:
陣列 (一)
[打印本頁]
作者:
鄭又綸
時間:
前天 13:19
標題:
陣列 (一)
本帖最後由 鄭又綸 於 2025-4-29 17:45 編輯
假設五年級共有8個班: 1班有30人, 2班有31人, 3班有33人, 4班有32人, 5班有31人, 6班有35人, 7班有28人, 8班有29人. 試利用陣列與for迴圈, 列出五年級各班的人數.
C++_Array
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n[8]={30,31,33,32,31,35,28,29};
for(int i=0; i<8; i++)
cout<<"5年"<<i+1<<"班有"<<n[i]<<"人"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
王繼樟
時間:
前天 20:10
此帖僅作者可見
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://www.istak.org.tw/seed/)
Powered by Discuz! 7.2