/*
数入字符串:123asd
反转后:dsa321
Press any key to continue
*/
#include
#define MAXlen 100
int length(char *s) {
int 岁模len = 0;
while(s[len]) ++len;
return len;
}
void convert(char *s) {
int i,len = length(s);
char ch;
for(i = 0; i < len/2; ++i) {
ch = s[i];
s[i] = s[len - 1 - i];
s[len - 1 - i] = ch;
}
}
int main() {
char 昌雀蔽str[MAXlen];
printf("数耐州入字符串:");
gets(str);
convert(str);
printf("反转后:%s\n",str);
return 0;
}
挺简单啊
int length(char *s)
{
int i=0;
while(s[i++]);
return i;
}
反序也不难握岩,神卜就是循游皮穗环一半
void convert(char *s)
{
int i;
int k=length(s);
char t;
for(i=0;i
t=s[i];
s[i]=s[k-i-1];
s[k-i-1]=t;
}
}
#include
int length(char *s)
{
int num = 0;
if(s == NULL)
return num;
while(s[num] != '\0')
{
num++;
}
return num;
}
void convert(char *s)
{
int size = length(s);
char ch;
for (int i = 0; i < size/2; ++i)
{
ch = s[i];
s[i] = s[size - i - 1];
s[size - i - 1] = ch;
}
}
int main()
{
char str[20];
scanf("%s",str);
convert(str);
printf("知知%s\n", str);
return 0;
}
//没验证 ,我这里没工具,在衫猛山文或中本上编的,有不懂的在问
// 兵无常势,水无常形,只用递归,不用循环
#include
#define SWAP(a,b) a^=b^=a^=b
void convert(char *s, int n)
{
if (n>1)
{
SWAP(*s, *(s+n-1));
激纯convert(s+1, n-2);
袜铅渣 }
}
int length(char *s)
{
告悄 return *s ? 1 + length(s+1) : 0;
}
void main()
{
char str[BUFSIZ];
printf("Input String: ");
gets_s(str, BUFSIZ);
convert(str, length(str));
printf("The convert string is <%s>\n", str);
getchar();
}