倒序--逆序=2

 先输出元素个数n,,,分别输出n个元素

#include <stdio.h>
void f(int a[],int n)
{    int i,t;
    for (i=0; i<n/2;i++)
    {    t=a[i]; a[i]=a[n-1-i]; a[n-1-i]=t; }
}
int main()
{    int a[200],n,i,x;
    while(scanf("%d",&n)!=EOF)
    {    for (i=0; i<n; i++)  scanf("%d",&a[i]);
        f(a,n);
        for (i=0; i<n-1; i++)  printf("%d ",a[i]);
        printf("%d
",a[n-1]);  
    }
} 
View Code

#include <stdio.h>
void f(int a[],int n)
{ int i,t;
for (i=0; i<n/2;i++)
{ t=a[i]; a[i]=a[n-1-i]; a[n-1-i]=t; }
}
int main()
{ int a[200],n,i,x;
while(scanf("%d",&n)!=EOF)
{ for (i=0; i<n; i++) scanf("%d",&a[i]);
f(a,n);
for (i=0; i<n-1; i++) printf("%d ",a[i]);
printf("%d ",a[n-1]);
}
}

 

**********************************************************************************************************************************

#include <stdio.h>
void f(int a[],int n)
{    int i,t;
    for (i=0; i<n/2;i++)
    {    t=a[i]; a[i]=a[n-1-i]; a[n-1-i]=t; }
}
int main()
{   int N ;
  scanf("%d",&N);
  int a[N];
    int n,i,x;
    while(scanf("%d",&n)!=EOF)
    {    for (i=0; i<n; i++)  scanf("%d",&a[i]);
        f(a,n);
        for (i=0; i<n-1; i++)  printf("%d ",a[i]);
        printf("%d
",a[n-1]);  
    }
} 
View Code

#include <stdio.h>
void f(int a[],int n)
{ int i,t;
for (i=0; i<n/2;i++)
{ t=a[i]; a[i]=a[n-1-i]; a[n-1-i]=t; }
}
int main()
{ int N ;
scanf("%d",&N);
int a[N];
int n,i,x;
while(scanf("%d",&n)!=EOF)
{ for (i=0; i<n; i++) scanf("%d",&a[i]);
f(a,n);
for (i=0; i<n-1; i++) printf("%d ",a[i]);
printf("%d ",a[n-1]);
}
}

*****************************************************************************************************************************************

#include <stdio.h>
void f(int a[],int n)
{    int i,t;
    for (i=0; i<n/2;i++)
    {    t=a[i]; a[i]=a[n-1-i]; a[n-1-i]=t; }
}
int main()
{  

 
int n,i,x;
    while(scanf("%d",&n)!=EOF)
    {    
       int a[n];
    
    for (i=0; i<n; i++)  scanf("%d",&a[i]);
        f(a,n);
        for (i=0; i<n-1; i++)  printf("%d ",a[i]);
        printf("%d
",a[n-1]);  
    }
} 
View Code

#include <stdio.h>
void f(int a[],int n)
{ int i,t;
for (i=0; i<n/2;i++)
{ t=a[i]; a[i]=a[n-1-i]; a[n-1-i]=t; }
}
int main()
{


int n,i,x;
while(scanf("%d",&n)!=EOF)
{
int a[n];

for (i=0; i<n; i++) scanf("%d",&a[i]);
f(a,n);
for (i=0; i<n-1; i++) printf("%d ",a[i]);
printf("%d ",a[n-1]);
}
}

原文地址:https://www.cnblogs.com/2014acm/p/3901323.html