用c++写一个祝人生日快乐的程序带烟花
时间: 2023-03-24 20:04:15 浏览: 431
很高兴回答您的问题。以下是一个用 C 语言编写的祝人生日快乐的程序,带有烟花效果:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
void fireworks();
int main()
{
printf("祝你生日快乐!\n");
fireworks();
return ;
}
void fireworks()
{
int i, j, k;
srand((unsigned)time(NULL));
for (i = ; i < 10; i++) {
for (j = ; j < 80; j++) {
k = rand() % 10;
if (k == ) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
Sleep(50);
}
}
相关问题
用c++写一个祝人生日快乐的程序
很高兴回答您的问题!以下是一个用 C 语言编写的祝人生日快乐的程序:
#include <stdio.h>
int main() {
char name[20];
printf("请输入您的名字:");
scanf("%s", name);
printf("祝 %s 生日快乐!\n", name);
return ;
}
您可以在程序中输入您的名字,程序将输出祝福语“祝 xxx 生日快乐!”。希望您喜欢这个程序!
用Dev C++写祝陈嘉庚生日快乐的烟花代码
好的,以下是祝陈嘉庚生日快乐的烟花代码:
```c++
#include <graphics.h>
#include <conio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
initgraph(640, 480); // 初始化图形界面
srand(time(NULL)); // 设置随机数种子
// 循环绘制烟花
while (1) {
int x = rand() % 640; // 随机生成烟花的x坐标
int y = rand() % 480; // 随机生成烟花的y坐标
int r = rand() % 255; // 随机生成烟花的颜色
int g = rand() % 255;
int b = rand() % 255;
setlinecolor(RGB(r, g, b)); // 设置线条颜色
setfillcolor(RGB(r, g, b)); // 设置填充颜色
// 绘制烟花
for (int i = 0; i < 50; i++) {
int dx = rand() % 21 - 10; // 随机生成x方向的偏移量
int dy = rand() % 21 - 10; // 随机生成y方向的偏移量
line(x, y, x + dx, y + dy); // 绘制线条
delay(10); // 延时一段时间,使得烟花效果更好
}
// 绘制烟花爆炸后的颗粒
for (int i = 0; i < 50; i++) {
int dx = rand() % 21 - 10; // 随机生成x方向的偏移量
int dy = rand() % 21 - 10; // 随机生成y方向的偏移量
solidcircle(x + dx, y + dy, 2); // 绘制实心圆
delay(10); // 延时一段时间,使得烟花效果更好
}
cleardevice(); // 清空屏幕,准备绘制下一个烟花
}
getch(); // 暂停程序,等待用户按下任意键结束
closegraph(); // 关闭图形界面
return 0;
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)