将welcome to bit !依次向中心靠拢打印出来
程序员文章站
2022-07-14 19:51:25
...
将welcome to bit !依次向中心靠拢打印出来
#include<stdio.h>
#include<stdlib.h>
int main()
{
char arr[] = { "welcome to bit !" };
char arr1[] = { "****************" };
int H = strlen(arr)-1;//H=15 strlen函数求的是字符串的长度
int left = 0;//定义数组下标左边界
int right = H;//定义数组下标右边界
while (left <= right)//出口条件是left>right也就是保证数组arr2每一个值都被赋值过一遍
{
arr1[left] = arr[left];//数组arr的左边值依次给数组arr1左边赋值
arr1[right] = arr[right];
left++;
right--;
printf(" ");
printf("%s\n", arr1);//字符数组(字符串和字符)的输出格式
}
system("pause");
return 0;
}
结果奉上