首页 > 代码库 > C/C++输入数组
C/C++输入数组
1 int n=0; 2 printf("please enter the number:\n"); 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() == ‘\n‘) //遇到回车,终止 19 break; 20 a[i++] = num; 21 } 22 23 /* 24 数组大小未知时 25 */ 26 vector<int>b; 27 while (cin >> num) 28 { 29 if (cin.get() == ‘\n‘) //遇到回车,终止 30 break; 31 b.push_back(num); 32 33 } 34 cout << "程序终止了" << endl; 35 system("pause"); 36 return 0; 37 }
C/C++输入数组
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。