本文共 865 字,大约阅读时间需要 2 分钟。
题目:
从键盘输入一个句子(假设字符数小于100个),句子中的单词之间用空格分隔,句子必须以一个标点符号作为结尾,句子开头和末尾标点符号前均没有空格,以回车表示输入结束,请编程颠倒句中的单词顺序并输出。 函数原型:int Inverse(char str1[], char str2[][N]) 函数功能:将str1中的单词颠倒顺序后分别存入str2的每一行,返回str1中的单词数。 程序运行结果示例1: Input a sentence:you can cage a swallow can’t you?↙ you can’t swallow a cage can you?程序运行结果示例2:
Input a string:you are my sunshine!↙ sunshine my are you!程序运行结果示例3:
Input a sentence:I love you!↙ you love I!输入提示信息:"“Input a sentence:”"
输入格式: 用gets()函数 输出格式: 每个单词的输出格式:""%s “” (注意: %s后面有一个空格) 最后一个单词和标点符号的输出格式:""%s%c\n""#include#include #define N 100int Inverse(char str1[], char str2[][N]);int Inverse(char str1[], char str2[][N]){ int i,j=0,t=0,len=strlen(str1); for(i=0;i =0;i--) { if(i!=0) printf("%s ",str2[i]); else printf("%s",str2[i]); } printf("%s%c\n",str2[t+1]);}
转载地址:http://edbrz.baihongyu.com/