TA的每日心情 | 开心 2014-6-18 08:29 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
滴水大师
 
- 积分
- 2345
|
题目
解决代码及点评
- <pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">/************************************************************************/
- /*
- 13. 将字符数组 A中下标为双号(0,2,4,6,8...) 的元素值传给另一个字符数组 B,
- 然后将 B数组的元素按逆序输出。
-
- */
- /************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
-
-
- void main()
- {
- char *p="abcdefghi";
- char To[20]; // 目标字符串
- int n=strlen(p); // n指向\0
- int i=0;
- int j=0;
- while (i<n) // 遍历字符串
- {
- To[j++]=*(p+i); // 将源字符串的内容拷贝到目标位置
- i+=2; // 步长为2,这样就只拷贝偶数下标的字符串了
- }
- To[j]='\0'; // 最后位置要置\0
- printf("%s\n",p);
-
- while(j>0) // 逆序输出
- {
- printf("%c",To[j-1]);
- j--;
- }
-
- system("pause");
- }</pre><br><br></pre>
|
|