本题要求编写程序,将给定的n个整数存入数组中,将数组中的这n个数逆序存放,再按要求输出指定的数组元素。
输入格式:
在第一行中给出一个正整数n(1≤n≤10)。第二行输入n个整数,用空格分开。第三行输入一个非负整数m(m<n)。
输出格式:
在一行中输出逆序存放后下标为m的数组元素。行末无空格。
输入样例:
6
10 8 1 2 3 4
2
输出样例:
2
本题要求编写程序,将给定的n个整数存入数组中,将数组中的这n个数逆序存放,再按要求输出指定的数组元素。
输入格式:
在第一行中给出一个正整数n(1≤n≤10)。第二行输入n个整数,用空格分开。第三行输入一个非负整数m(m<n)。
输出格式:
在一行中输出逆序存放后下标为m的数组元素。行末无空格。
输入样例:
6
10 8 1 2 3 4
2
输出样例:
2
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,m;
scanf("%d",&n);
if(n<1||n>10){
printf("1≤n≤10");
return 0;
}
int *a = (int*)malloc(sizeof(int)*n);
for(int i=n-1; i>=0; i-- ){
scanf("%d",&a[i]);
}
scanf("%d",&m);
if(m<0||m>=n){
printf("0≤m<n");
return 0;
}
printf("%d",a[m]);
return 0;
}