c语言 字符串数组倒序输出
2 回答
慕斯709654
TA贡献1840条经验 获得超5个赞
| 123456789101112131415161718192021222324 | /*定义一个函数reverse,该函数的参数为一个字符数组,函数的功能为将输入的字符串倒转后的字符数组。例:reverse("abcd")输出为"dcba"。*/#include<stdio.h>void reverse(char *s){ int n=0; while (*s!='\0') { s++; n++; } s--; while (n) { printf("[%c]",*s--); n--; } } void main(){ char a[10] ="abcd"; reverse(a);}[d][c][b][a]Press any key to continue |
添加回答
举报
0/150
提交
取消
