编写一个 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 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短