C語言二維陣列指標練習
阿新 • • 發佈:2018-11-16
描述
程式填空,使其輸出結果是: 1,2,3,4, 10,12,14,16, 18,20,11,12,
#include <iostream> using namespace std; void Double(int * p, int n) { for(int i = 0;i < n; ++i) p[i] *= 2; } int main() { int a[3][4] = { { 1,2,3,4},{5,6,7,8}, { 9,10,11,12 } }; Double(
// 在此處補充你的程式碼
); for(int i = 0;i < 3; ++i) { for(int j = 0; j < 4; ++j) cout << a[i][j] << ","; cout << endl; } return 0; }
輸入
無
輸出
1,2,3,4,
10,12,14,16,
18,20,11,12,
樣例輸入
無
樣例輸出
1,2,3,4, 10,12,14,16, 18,20,11,12,
來源
Guo Wei
練習二維陣列指標的運用
#include <iostream> using namespace std; void Double(int * p, int n) { for (int i = 0; i < n; ++i) p[i] *= 2; } int main() { int a[3][4] = { { 1,2,3,4 },{ 5,6,7,8 }, { 9,10,11,12 } }; Double(a[1],6 // 在此處補充你的程式碼 ); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 4; ++j) cout << a[i][j] << ","; cout << endl; } return 0; }