首页 > 试题广场 >

编写一个程序把一个单词读入一个字符数组,然后反向打印出这个词

[问答题]

编写一个程序把一个单词读入一个字符数组,然后反向打印出这个词。提示:使用strlen()(第4章)计算数组中最后一个字符的索引。

推荐
#include<stdio.h>
#include<string.h>
int main(void)
{
 char word[20];
 int i;
 printf("Please input a word:");
 scanf("%s",&word);
 for(i=strlen(word)-1;i>=0;i--)
 printf("%c",word[i]);
 printf("\n");
 return(0);
}

发表于 2018-05-05 21:36:09 回复(0)