c++开了一个10000的一维数组,输入后程序无反应

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
unsigned int  ans[10000];
int main()
{
    for (int i = 0; i <10000; ++i)
    {
       cin>>ans[i];
    }
    for (int i = 0; i <10000; ++i)
    {
        cout << ans[i] << " ";
    }    
}

你第一个for循环,需要输入10000次才会结束。你确定你输入10000次了?可以修改为:

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
unsigned int  ans[10000];
int main()
{
	int n;
	cout << "请输入数据的个数:"<< endl;
	cin >>n;
	for (int i = 0; i <n; ++i)
	{
		cin>>ans[i];
	}
	for (int i = 0; i <10000; ++i)
	{
		cout << ans[i] << " ";
	}    
}

 

1. 你的代码for循环是要输入1万次;

2. 不建议在栈上申请这么大的数组;