首页 行业资讯 宠物日常 宠物养护 宠物健康 宠物故事

如何用C语言编程一个移动的爱心

发布网友

我来回答

2个回答

热心网友

//一个非常简陋的实现,看看行不行
#include<iostream>
#include<windows.h>
using namespace std;

int main()
{
char heart[10][10]=
{
{' ',' ','*','*',' ','*','*',' ',' ',' '},
{' ','*',' ',' ','*',' ',' ','*',' ',' '},
{' ','*',' ',' ','*',' ',' ','*',' ',' '},
{' ','*',' ',' ',' ',' ',' ','*',' ',' '},
{' ',' ','*',' ',' ',' ','*',' ',' ',' '},
{' ',' ','*',' ',' ',' ','*',' ',' ',' '},
{' ',' ',' ','*',' ','*',' ',' ',' ',' '},
{' ',' ',' ','*',' ','*',' ',' ',' ',' '},
{' ',' ',' ',' ','*',' ',' ',' ',' ',' '},
{' ',' ',' ',' ',' ',' ',' ',' ',' ',' '},
};
int index=0;
while(1){
for(int i=0;i<10;++i){
for(int ii=0;ii<index;++ii)
cout<<' ';
for(int j=0;j<10;++j)
cout<<heart[i][j]<<' ';
cout<<endl;
}
index=(index+1)%15;
Sleep(300);
system("cls");
}
return 1;
}

热心网友

//因为命令行不认识♥,所以运行起来♥会变成?,但原理相同。
#include
<windows.h>
void
main(void)
{
printf("♥\n");
Sleep(1000);
//
延时一秒
system("cls");//清屏
printf("
♥\n");
Sleep(1000);//延时一秒
system("cls");//清屏
printf("
♥\n");
Sleep(1000);//延时一秒
system("cls");//清屏
printf("
♥\n");
getch();}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com