本文介绍了字符串反转问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 为什么不: #include< stdio.h> void reverse(char [],int) ; main() { char s [5]; s [0] =''h''; s [1] =''e''; s [2] =''l''; s [3] =''l''; s [4] =''o''; reverse(s,5); for(int i = 0; i< = 4; i ++) putchar(s [i]); 返回0 ; } void reverse(char s [],int num_elements) { int i,j; for(i = 0,j = num_elements-1;(i< = num_elements-1)&&(j> = 0); i ++, j--) s [i] = s [j]; } 输出: olleh ?Why doesn''t:#include <stdio.h>void reverse(char[], int);main(){char s[5];s[0] = ''h'';s[1] = ''e'';s[2] = ''l'';s[3] = ''l'';s[4] = ''o'';reverse(s, 5);for (int i=0; i<=4; i++)putchar(s[i]);return 0;}void reverse(char s[], int num_elements){int i, j;for (i=0,j=num_elements-1; (i<=num_elements-1) && (j>=0); i++,j--)s[i] = s[j];}output:olleh?推荐答案 HTH, --ag - Artie Gold - 德克萨斯州奥斯汀 http://goldsays.blogspot.com (新帖子8/5) http://www.cafepress.com/goldsays 如果你没有什么可隐瞒的,你就不会尝试!HTH,--ag--Artie Gold -- Austin, Texas http://goldsays.blogspot.com (new post 8/5) http://www.cafepress.com/goldsays"If you have nothing to hide, you''re not trying!" 这篇关于字符串反转问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-05 18:08