跳动的爱心的C语言代码
时间: 2023-08-02 07:43:16 浏览: 218
以下是跳动的爱心C语言代码:
```c
#include <stdio.h>
#include <windows.h>
void heart_animation() {
const char* heart = "\033[91m ♥♥ \033[0m";
const char* empty_heart = " ";
const char* heart_list[] = {empty_heart, empty_heart, empty_heart, empty_heart, empty_heart, empty_heart, heart, heart, empty_heart};
while (1) {
for (int i = 0; i < 9; i++) {
Sleep(100);
printf("%s\n", heart_list[i]);
const char* temp = heart_list[8];
for (int j = 8; j > 0; j--) {
heart_list[j] = heart_list[j-1];
}
heart_list[0] = temp;
if (i == 8) {
heart_list[0] = empty_heart;
heart_list[1] = empty_heart;
heart_list[2] = empty_heart;
heart_list[3] = empty_heart;
heart_list[4] = empty_heart;
heart_list[5] = empty_heart;
heart_list[6] = heart;
heart_list[7] = heart;
heart_list[8] = empty_heart;
}
}
}
}
int main() {
heart_animation();
return 0;
}
```
运行代码会输出一个跳动的爱心动画。注意,这个代码在Windows下运行的效果可能会比较好,因为它使用了Windows API中的Sleep函数。如果在Linux或其他系统下运行,你需要将Sleep函数替换成相应的等待函数。
阅读全文