编写一个 C 程序,在字符串中使用 for 循环以相反的顺序打印消息
这里我们编写了一个程序,在没有预定义函数的情况下反转句子。通过使用for循环,我们可以轻松地以相反的顺序打印语句。
方案一
#include输出结果int main(){ char stmt[100]; int i; printf("enter the message:\n"); for(i=0;i =0;i--) //以相反的顺序打印每个字符 putchar(stmt[i]); putchar('\n'); return 0; }
enter the message: Hi welcome to my world the reverse statement is: dlrow ym ot emoclew iH
方案二
在这里,我们将编写一个C程序来使用strrev库函数反转字符串-
#include输出结果#include void main(){ //Declaring two strings// char result[50],string[25]; //Reading string 1 and String 2// printf("输入要反转的字符串: "); gets(string); //Reversing using library function// strrev(string); printf("反转的字符串是: "); puts(string); }
输入要反转的字符串: Hi welcome to tutorials Point 反转的字符串是: tnioP slairotut ot emoclew iH
热门推荐
10 男童毕业蛋糕祝福语简短
11 足球队祝福语简短
12 我想找祝福语大全简短
13 春天变冷祝福语简短
14 宝子生日祝福语简短
15 夸赞老师祝福语搞笑简短
16 比赛结束花束祝福语简短
17 祖国七十华诞简短祝福语
18 新年简短的祝福语爱情