输出一段话,开始都是*,从两边逐渐向中间展开(结果为动态,不要错过)

打印“Welcome to my blog!!!”这句话,但是要先输出一串“ ********************** ”,然后由两边向中间逐渐展开

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

 int main()
 {
 	char arr1[] = "Welcome to my blog!!!";
 	char arr2[] = "*********************";
 	int left = 0;
 	int right = strlen(arr1)-1;

	printf("%s\n", arr2);
	Sleep(1000);
	system("cls");

	while (left <= right)
 	{
 		arr2[left] = arr1[left];
 		arr2[right] = arr1[right];
 		printf("%s\n", arr2);
 		Sleep(1000);
 		system("cls");
 		left++;
 		right--;
 	}

 	return 0;

 }

因为这里是一个动态结果演示,所以可以粘贴到自己的编译器上去看。

大家可以把内容修改一下,自己也试试,这里我把代码中出现的两句代码解释一下:

1.Sleep(1000);          

 Sleep函数功能: 执行挂起一段时间(这里时间单位是毫秒ms)    调用此函数需引入头文件#include <windows.h>

2.system("cls");

system("cls")用于清屏功能          调用system()函数需引入头文件#include <stdlib.h>

 

 

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的单片机C语言程序实现流水灯中间两边,再从两边中间亮的示例: ```c #include <reg52.h> // 导入单片机寄存器头文件 sbit LED1 = P0^0; // 定义LED1连接的单片机引脚 sbit LED2 = P0^1; // 定义LED2连接的单片机引脚 sbit LED3 = P0^2; // 定义LED3连接的单片机引脚 sbit LED4 = P0^3; // 定义LED4连接的单片机引脚 sbit LED5 = P0^4; // 定义LED5连接的单片机引脚 sbit LED6 = P0^5; // 定义LED6连接的单片机引脚 sbit LED7 = P0^6; // 定义LED7连接的单片机引脚 sbit LED8 = P0^7; // 定义LED8连接的单片机引脚 void delay(unsigned int); // 定义延时函数 void main() { while(1) { // 无限循环 LED1 = LED2 = LED3 = LED4 = 0; // 关闭所有LED灯 LED5 = LED6 = LED7 = LED8 = 0; // 从中间两边点亮 LED4 = LED5 = 1; // 点亮中间的两个LED灯 delay(500); // 延时500毫秒 LED3 = LED6 = 1; // 点亮中间两边的LED灯 delay(500); LED2 = LED7 = 1; // 点亮外面的两个LED灯 delay(500); LED1 = LED8 = 1; // 点亮最外面的两个LED灯 delay(500); // 从两边中间点亮 LED1 = LED8 = 0; // 先熄灭最外面的两个LED灯 delay(500); LED2 = LED7 = 0; // 再熄灭外面的两个LED灯 delay(500); LED3 = LED6 = 0; // 再熄灭中间两边的LED灯 delay(500); LED4 = LED5 = 0; // 最后熄灭中间的两个LED灯 delay(500); } } void delay(unsigned int xms) { // 延时函数的实现 unsigned int i, j; for(i=xms; i>0; i--) for(j=110; j>0; j--); } ``` 这个程序的实现方式是通过循环控制LED灯的点亮和熄灭,使用了一个简单的延时函数来控制时间。在每个步骤中,需要控制好LED的点亮和熄灭的顺序和时间,使得LED灯能够按照要求顺序点亮和熄灭。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值