超简单C语言问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 02:10:47
要求将输入的一串字符按逆序输出,如输入123456,则输出654321.
下面的程序错了,错在哪里,怎么改正,为什么要这么改:
main()
{
char x[80],m;int a,i;
printf("shu ru zi fu chuan:");
gets(x);
a=strlen(x);
for(i=0;i<a%2;i++)
{m=x[a-1-i];
x[a-1-i]=x[i];
x[i]=m;}
printf("%c",x);

}

#include<stdio.h>
#include<string.h>
#define N 10
void main()
{ char str[N];
int i;
printf("Please input the string:\n");
gets(str);
printf("The reverse order is :\n");
for(i=strlen(str)-1;i>=0;i--)
printf("%c",str[i]);
}
测试数据: 56987f,dDa
输出结果: aDd,f78965
写程序一定要注意风格!!

#include <stdio.h>
#include<string.h>
void main(){

char x[80],m;int a,i;
printf("shu ru zi fu chuan:");
gets(x);
a=strlen(x);
for(i=0;i<a/2;i++)
{m=x[a-1-i];
x[a-1-i]=x[i];
x[i]=m;}
printf("%s\n",x);

}

首先循环条件是a/2,并不是a对2求余,还有最后输出是字符串形式输出!

为什么要搞那么复杂 能简单的就用简单的
# include "stdio.h"
# include "string.h"
void main()
{
char x[80],m;int a,i;
printf("shu ru zi fu chuan:");
gets(x);