编写一个 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
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下