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
提交
取消
