这个包含数字数组的C ++代码有问题

时间:2015-03-25 09:42:51

标签: arrays

任何人都可以弄清楚为什么它运行正常然后告诉我之后的错误,一切正常,但它说有一个"数字"错误



#include <iostream>

int main(int argc, char* argv[])
{
	int number[3][3];
	int Temporary;

	std::cin >> Temporary;
	number[0][0]  = Temporary;
		 std::cin >> Temporary;
	number[0][1] = Temporary;
		 std::cin >> Temporary;
	number[0][2] = Temporary;
		 std::cin >> Temporary;
	number[1][0] = Temporary;
		 std::cin >> Temporary;
	number[1][2] = Temporary;
		 std::cin >> Temporary;
	number[1][1] = Temporary;
		 std::cin >> Temporary;
	number[3][0] = Temporary;
		 std::cin >> Temporary;
	number[3][1]  = Temporary;
		 std::cin >> Temporary;
	 number[3][2] = Temporary;

	std::cout << number[0][0] << number[0][1] << number[0][2] << std::endl;
	std::cout << number[1][0] << number[1][1] << number[1][2] << std::endl;
	std::cout << number[3][0] << number[3][1] << number[3][2] << std::endl;

	
	system("pause");
		return 0;
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您的操作超出了数组的范围。您应该使用2作为第一个索引,而不是3。这意味着number[2][1]而不是number[3][1]

对于定义int number[N][N];,有效索引范围从0到N-1。