c++数组问题 如何得到你想要的第几个数 比如把10个任意整数输入到一个数组中 我想得到这个数组中

c++数组问题 如何得到你想要的第几个数
比如把10个任意整数输入到一个数组中 我想得到这个数组中的第三个数并且输出 怎么做到?求编程

#include<iostream>
using namespace std;

int main()
{
//定义数组

int array[10];
//循环输入十个数

for(int i = 0;i<10;i++)
cin>>array[i];
//输出第三个数,数组下标从0开始,0、1、2

cout<<array[2]<<endl;
return 0;

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-12-10
。。。。最简单的下标表示啊。
例如定义
int a[10]={1,2,3,4,5,6,7,8,9,10};
表示从a[0]~a[9];

其中a[0]表示第一个元素1;
你要数组第三个的话就是a[2],printf("%d",a[2]);追问

不要一开始就定义 要自己输入的 还有你那个printf是C语言吧 我看不懂

第2个回答  2014-12-10
#include<iostream>
#include <stdlib.h>
using namespace std;
int main()
{
long arr[10];
cout << "Please input 10 numbers:" << endl;
for (int i = 0; i < 10; i++)
{
cin >> arr[i];
}
cout << "The third number is :" << arr[2] << endl;
system("pause");
return 0;
}