?编写代码,演示多个字符从两端移动,向中间汇聚。
代码示例:
#include <stdio.h>
#include <string.h>
int main()
{
char arr1[] = "Nothing is impossible!";
char arr2[] = "######################";
int left = 0;
int right = strlen(arr1) - 1;//strlen计算字符串的长度,遇到/n停止计数(不包括/n长度)
printf("%s\n", arr2);
while (left <= right)
{
arr2[left] = arr1[left];
arr2[right] = arr1[right];
left++;
right--;
printf("%s\n", arr2);
}
return 0;
}
运行结果:
######################
N####################!
No##################e!
Not################le!
Noth##############ble!
Nothi############ible!
Nothin##########sible!
Nothing########ssible!
Nothing ######ossible!
Nothing i####possible!
Nothing is##mpossible!
Nothing is impossible!