나는이 특정 코드를 C++로 작성하여 while 루프를 사용하고 정수 배열에 저장하여 정수 3 & 5의 모든 배수를 찾으려고했습니다. 또한 각 배수를 인쇄하고 싶습니다. 하지만이 프로그램을 디버깅 할 때마다 끝없이 '0'이 인쇄됩니다. 나는 이해하지 못한다. 누군가이 코드를 수정하는 방법과 그 비정상적인 결과가 나타나는 이유를 설명해 주시겠습니까?정수 배수 빠르게 찾기
#include <iostream>
using namespace std;
int main()
{
const int three_limit = 334;
const int five_limit = 200;
int threeArray[three_limit] = {0};
int fiveArray[five_limit] = {0};
int i = 1, j = 1;
while (i < three_limit)
{
int multiples = 3*i;
multiples = threeArray[i - 1];
cout << threeArray[i - 1] << endl;
i++;
}
while (j < five_limit)
{
int multiples = 5*i;
multiples = fiveArray[j - 1];
cout << fiveArray[j - 1] << endl;
j++;
}
char response;
cin >> response;
return 0;
}
'='연산자의 순서를 확인하십시오. –
'multiples = threeArray [i - 1];'및'multiples = fiveArray [j - 1];'에서 당신은 분명히 왼쪽에서 오른쪽으로 할당하려고합니다. 할당은 오른쪽에서 왼쪽으로 진행됩니다. 또한이 질문을 숙제로 표시하십시오. –