演示多个字符串从两端移动,向中间汇聚
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define SIZE 12
int main() {
char arr1[SIZE] = "Hello World!";
char arr2[SIZE] = "############";
int left = 0;
int right = SIZE - 1;
while (left <= right) {
arr2[left] = arr1[left];
arr2[right] = arr1[right];
left++;
right--;
printf("%s\n", arr2);
system("cls");
}
system("pause");
return 0;
}
编程思路:
首先进行宏定义来确定字符数组的长度为SIZE;
其次是给定字符串备用,采用while循环实现left自增和right自减,并且交换字符arr1和arr2的值;(此处的while循环可以用for循环代替)
最后打印出结果。
注意,此处的system(“cls”)指的是:clear screen.(清空显示器)。