如何用c语言中的数组来实现“i love you ”变成“you love i”

来源:百度知道 编辑:UC知道 时间:2024/05/20 17:36:37
或者数组结合指针也可以
最好是比较精简的算法,
使用一维数组

#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>

void reverse(int nN,char* b,char *c)
{
char temp;
for(int i=0;i<(nN/2);++b,--c,++i)
{
temp=*b;
*b=*c;
*c=temp;
}
}

void printS(char *s)
{
cout<<s<<endl;
}

int main()
{
char s[100],*h,*t;
int n=0;
cout<<"Please input your words: "<<endl;
gets(s);
h=t=s;
while(*t)
{
++n;
++t;
}
--t;
reverse(n,h,t);
printS(s);
return 0;

}

#define N 3
#include<stdio.h>
main()
{
char str[N][20];
int i=0,j;
scanf("%s %s %s",str[i],str[i+1],str[i+2]);

for(i=0;i<N;i++)
printf("%s ",str[i]);
printf("\n");
for(i=N-1;i>=0;i--)
printf("%s &quo