用C语言编程:将一个数组中的值按逆序重新存放。

来源:百度知道 编辑:UC知道 时间:2024/05/05 21:19:37
谢谢```

#include "stdio.h"
#include "conio.h"
#include "dos.h"
void main(void)
{
int a[10],b[10];
int i=0;
for(i=0;i<10;i++)
{
a[i]=i;
printf("%d ",a[i]);
}
printf("\n");

for(i=0;i<10;i++)
b[9-i] = a[i];

for(i=0;i<10;i++)
{
a[i] = b[i];
printf("%d ",a[i]);
}

}

一个例子,希望能对你有所启发

char *p_start,*p_end;
char ch[100];
int i=0;
int temp;
p_start=ch;
p_end=ch+100;
for(;i<=100/2;i++)
{
temp=*p_start;
*p_start=*p_end;
*p_end=temp;
}

或者直接使用C提供的库函数strrev()实现

不用那么多吧

void inverse(int b[],int n)
{
int i,j,t;
for(i=0,j=n-1;i<j;i++,j--)
{
t=b[i]; b[i]=b[j]; b[j]=t;
}

}