编写代码,演示多个字符从两端移动,向中间汇聚。

    xiaoxiao2025-03-24  34

    编写代码,演示多个字符从两端移动,向中间汇聚。

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <Windows.h> //系统库头文件 int main() { char str1[] = "welcome to my blog!"; char str2[] = "###################"; int left = 0; int right = strlen(str1) - 1; //数组最右端的下标 while (left <= right) { printf("%s\n", str2); str2[left] = str1[left]; str2[right] = str1[right]; ++left; --right; Sleep(500); //减慢运行速度 Sleep 的单位是毫秒 system("cls"); //清屏,让代码在同一行打印 } system("pause"); return 0; }
    最新回复(0)