1 int n=0; 2 printf("please enter the number: "); 3 scanf("%d",&n); 4 5 int *number=new int[n]; 6 7 for(int i=0;i<n;++i) 8 scanf("%d ",&number[i]);
1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 5 6 7 8 9 int main() 10 { 11 /* 12 已知数组的大小,使用动态数组 13 */ 14 int i = 0; 15 int num; 16 int * a = new int[5]; 17 while (cin >> num ) { 18 if (cin.get() == ' ') //遇到回车,终止 19 break; 20 a[i++] = num; 21 } 22 23 /* 24 数组大小未知时 25 */ 26 vector<int>b; 27 while (cin >> num) 28 { 29 if (cin.get() == ' ') //遇到回车,终止 30 break; 31 b.push_back(num); 32 33 } 34 cout << "程序终止了" << endl; 35 system("pause"); 36 return 0; 37 }