实现字符串的倒置

任务描述

本关任务: 编程实现字符串的倒置,如输入字符串为:"ABCDEF",倒置为"EFDCBA"。

相关知识

为了完成本关任务,你需要掌握: 1.字符串倒置的算法, 2.字符串函数:strlen,gets和puts的用法。

编程要求

1.从键盘输入任意字符串; 2.根据提示,在编辑器补充代码,完成字符串的倒置。

测试说明

平台会对你编写的代码进行测试:

输入:ABCDEFG 输出:GFEDCBA

#include <stdio.h>
#include <string.h>
main()
{
	char str[100];
	int i,j,k;
	int len;
	printf("请输入字符串:\n");
 gets(str);
	j=strlen(str)-1;
	for(i=0;i<j;i++,j--)
{
k=str[i];
str[i]=str[j];
str[j]=k;
}
    printf("字符串倒置为:");
    puts(str);
}

猜你喜欢

转载自blog.csdn.net/qq_46069852/article/details/121368129