题目
解决代码及点评
/************************************************************************/
/*
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");
}
代码下载及其运行
代码下载链接:
http://download.csdn.net/detail/yincheng01/6653839
解压密码为c.itcast.cn
下载解压后用VS2013打开工程文件
点击 “本地Windows调试器” 执行
程序运行结果