1 개요[ | ]
- C++ 배열 fill()
- C++ 배열 동일한 값으로 채우기
- C++ 배열 모두 같은 값으로 채우기
2 1차원 배열[ | ]
C++
CPU
0.3s
MEM
47M
0.3s
Copy
#include <iostream>
using namespace std;
int main() {
int A[5] = {1, 2, 3, 4, 5};
fill(A, A+5, 100);
for(int i=0; i<5; i++) cout << A[i] << ' '; // 100 100 100 100 100
}
100 100 100 100 100
C++
Copy
#include <iostream>
using namespace std;
int main() {
int A[5] = {1, 2, 3, 4, 5};
for(int i=0; i<5; i++) A[i] = 100;
for(int i=0; i<5; i++) cout << A[i] << ' '; // 100 100 100 100 100
}
Loading
3 2차원 배열[ | ]
C++
Copy
#include <iostream>
using namespace std;
int main() {
int A[3][4];
fill(A[0], A[0]+12, 100);
for(int i=0; i<3; i++) {
for(int j=0; j<4; j++) cout << A[i][j] << ' ';
cout << endl;
}
}
Loading
C++
Copy
#include <iostream>
using namespace std;
int main() {
int A[3][4];
for(int i=0; i<3; i++) {
for(int j=0; j<4; j++) A[i][j] = 100;
}
fill(A[0], A[0]+12, 100);
for(int i=0; i<3; i++) {
for(int j=0; j<4; j++) cout << A[i][j] << ' ';
cout << endl;
}
}
Loading
4 같이 보기[ | ]
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.