[C++] 14. 배열

2022. 5. 30. 21:46코딩 1막 <C++개념편>

728x90

#include <iostream>

using namespace std;


void main()
{
int scoreA = 70;
int scoreB = 20;
int scoreC = 90;
int scoreD = 0;
int scoreE = 80;


// 배열
// index라는 개념이 있기때문에 바로 바로 참조 가능

int scores[] = { 70, 20, 90, 0, 80 };
int maxValue = 0;
int maxIndex = 0;

//sizeof
cout << sizeof(int) << endl;
cout << sizeof(scores) << endl;
cout << sizeof(scores[0]) << endl;
cout << sizeof(scores) / sizeof(scores[0]) << endl;

cout << endl;

for (int i = 0; i < 5; i++)
{
if (scores[i] > maxValue)
{
maxValue = scores[i];
maxIndex = i + 1;
}
cout << scores[i] << endl;
}
cout << "최고 값 : " << maxValue << endl;
cout << "최고 값의 위치 : " << maxIndex << endl;
}

출력 결과

 

728x90

'코딩 1막 <C++개념편>' 카테고리의 다른 글

[C++] 16. 2차원배열  (0) 2022.05.31
[C++] 15. sizeof()  (0) 2022.05.31
[C++] 13. 포인터변수  (0) 2022.05.30
[C++] 12. 피보나치 수열 문제  (0) 2022.05.30
[C++] 11. 재귀함수  (0) 2022.05.30