用C语言写一个跳动的爱心
时间: 2023-12-29 08:03:31 浏览: 83
用C语言编写爱心
好的,以下是C语言实现跳动的爱心的代码:
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
void SetCursorPosition(int x, int y)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = {x, y};
SetConsoleCursorPosition(handle, position);
}
int main()
{
int x = 40, y = 10, i = 0;
while (1) {
SetCursorPosition(x, y);
if (i % 2 == 0) {
printf(" * * ");
SetCursorPosition(x, y+1);
printf(" * * * * ");
SetCursorPosition(x, y+2);
printf("* * *");
} else {
printf("* *");
SetCursorPosition(x, y+1);
printf(" * * ");
SetCursorPosition(x, y+2);
printf(" * * ");
}
i++;
Sleep(500);
system("cls");
}
return 0;
}
阅读全文