反向输出字符数组

版权声明:由陈庚汝编辑 https://blog.csdn.net/ChenGengru/article/details/85236843

运用了for循环语句和strlen函数
代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/* 反转输出字符串.c */
/* written by Chen Gengru */
/* updated on 2018-12-24 */

int main()
{
	char text[20];
	int i;
	
	printf("输入字符串:\n");
	scanf("%s", &text);
	
	for (i = strlen(text)-1; i >= 0; i--)
	{
		printf("%c", text[i]);
	}
	
	printf("\n");
	return 0;
 } 

结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/ChenGengru/article/details/85236843