hello world还有这种写法

hello world还有这种写法,第1张

hello world还有这种写法

用while循环来实现hello world 从两边往中间逐渐显示,代码学习于比特。想看效果的可以去运行一下。

#include
#include//调用strlen()函数
#include//调用Sleep()函数
#include//调用system()函数
int main()
{
	char arr1[]="Hello world!!!";//给定字符
	char arr2[]="##############";//利用#来做到字符从两端移动
	int left=0;//定义左光标
	int right=strlen(arr1)-1;//右光标
	while(left<=right)//循环条件
	{
		arr2[left]=arr1[left];//实现字符移动
	    arr2[right]=arr1[right];//同理
	    printf("%sn",arr2);//打印出来
		Sleep(1000);//控制打印时间为1秒
		system("cls");//打印一次清空屏幕
	    left++;//每次光标往右移动一位
	    right--;//光标往左移动一位
	}
	printf("%sn",arr2);//cls会清空屏幕,最终重新打印一次在屏幕上
	return 0;

}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5699201.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-17
下一篇2022-12-17

发表评论

登录后才能评论

评论列表(0条)

    保存