编写一个 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 红包祝福语简短10字
18 周六早晨祝福语简短