第15周OJ实践3 字符串逆序输出
原创
©著作权归作者所有:来自51CTO博客作者mb614decb9ad0b0的原创作品,请联系作者获取转载授权,否则将追究法律责任
问题及代码:
Problem C: 字符串逆序输出
Time Limit: 1 Sec
Memory Limit: 128 MB
Submit: 609
Solved: 358
[
Submit][
Status][
Web Board]
Description
编写一个函数,功能是使输入的字符串逆序输出。
Input
输入一串字符串,注意字符串中不要有空格。
Output
输出该字符串的逆序。
Sample Input
Sample Output
#include<stdio.h>
#include<string.h>
int main()
{
char str[100];
scanf("%s",str);
int len;
len=strlen(str);
int fuction(char *, int);
fuction(str,len);
return 0;
}
int fuction(char * str, int len)
{
int i;
for(i=strlen(str); i>0; i--)
printf("%c",str[i-1]);
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i=0,j=0;
char x[100],c='a';
do
{
scanf("%c",&x[i]);
c=x[i];
i++;
}
while(c!='\n');
for(j=i,i=j-1;i>=0;i--)
printf("%c",x[i]);
return 0;
}
运行结果:

知识点总结:
strlen 功能:函数返回字符串str 的长度( 即空值结束符之前字符数目)。利用此完成逆序。