问题:对一批整数{2,4,6,8,10,12,14,16,18,20},在保持原始数据不变的情况下,按要求输出所有数据。
要求:输入m和n,把其中从m到n的数据逆序输出,其他位置的数据原样输出。(输出的每个数据占4列宽度)
如:输入4和8,则输出2 4 6 16 14 12 10 8 18 20
分析: 2,4,6,8,10,12,14,16,18,20--》int a[10]
输入m和n
设计一个函数(实现从m..n个数逆序)
t1=m-1;t2=m-2;
while (t1<t2)
{
s[t1]<---->s[t2];
t1++;t2--; }
void sort(int *s[],int m,int n) {
int t1,t2;
int *p;
t1=m-1;t2=n-1;
while (t1<t2) {
p=s[t1];s[t1]=s[t2];s[t2]=p; t1++;t2--; } }
int main(){
int a[10]={2,4,6,8,10,12,14,16,18,20};
int *s[10],i,m,n;
scanf("%d%d",&m,&n);
for(i=0;i<10;i++)
s[i]=&a[i];
sort(s,m,n);
for(i=0;i<10;i++)
printf("%4d",*(s[i]));return 0;}