1:字符数组的逆序输出
#include <stdio.h>
#include <string.h>
void swap(char *a)
{
int i = 0;
int len = strlen(a);
for(i=0;i<(len/2);i++)
{
char temp;
temp = a[i];
a[i] = a[len-i-1];
a[len-i-1] = temp;
}
printf("%s/n",a);
}
int main(int argc,char *argv[])
{
char a[] = "abcd";
char b[] = "abcde";
swap(a);
swap(b);
return 0;
}
2:整型数组的逆序输出
#include <stdio.h>
#include <string.h>
void swap(int *a,int len)
{
int i = 0;
for(i=0;i<(len/2);i++)
{
int temp;
temp = a[i];
a[i] = a[len-i-1];
a[len-i-1] = temp;
}
for(i=0;i<len;i++)
{
printf("%d ",a[i]);
}
printf("/n");
}
int main(int argc,char *argv[])
{
int a[] = {1,2,3,4};
int lena = sizeof(a)/sizeof(int);
int b[] = {1,2,3,4,5};
int lenb = sizeof(b)/sizeof(int);
swap(a,lena);
swap(b,lenb);
return 0;
}