c语言生日祝福源代码
时间: 2023-12-12 09:34:40 浏览: 306
以下是一份C语言生日祝福源代码,其中包含动态爱心和生日祝福语句:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
void SetColor(int color) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color);
}
void gotoxy(int x, int y) {
COORD pos = {x, y};
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsole, pos);
}
void drawHeart(int x, int y, int color) {
SetColor(color);
gotoxy(x, y);
printf(" ** **");
gotoxy(x, y+1);
printf(" **** ****");
gotoxy(x, y+2);
printf("**********");
gotoxy(x, y+3);
printf(" ********");
gotoxy(x, y+4);
printf(" ******");
gotoxy(x, y+5);
printf(" ****");
gotoxy(x, y+6);
printf(" **");
}
int main() {
char name[20];
printf("请输入你的名字:");
scanf("%s", name);
int len = strlen(name);
int x = 40 - len/2;
int y = 10;
int i, j;
for (i = 0; i < 7; i++) {
for (j = 0; j < 80; j++) {
if ((i == 0 && j % 6 == 0) || (i == 1 && j % 6 == 3) || (i == 2 && j % 6 == 1) || (i == 3 && j % 6 == 4) || (i == 4 && j % 6 == 2) || (i == 5 && j % 6 == 5)) {
drawHeart(j, i, 0xc);
}
}
}
SetColor(0xf);
gotoxy(x, y+7);
printf("亲爱的 %s:", name);
gotoxy(x, y+9);
printf("今天是你的生日,祝你生日快乐!");
gotoxy(x, y+11);
printf("愿你的每一天都充满阳光和快乐,");
gotoxy(x, y+13);
printf("愿你的每一个梦想都能实现,");
gotoxy(x, y+15);
printf("愿你的每一份付出都有回报,");
gotoxy(x, y+17);
printf("愿你的每一次努力都有收获!");
gotoxy(x, y+19);
printf("生日快乐!");
return 0;
}
```
阅读全文