c語言 字符串數(shù)組倒序輸出
2 回答

慕斯709654
TA貢獻1840條經(jīng)驗 獲得超5個贊
123456789101112131415161718192021222324 | /*定義一個函數(shù)reverse,該函數(shù)的參數(shù)為一個字符數(shù)組,函數(shù)的功能為將輸入的字符串倒轉(zhuǎn)后的字符數(shù)組。例: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
提交
取消