c语言程序设计显示图案,设计一个简易的爱心图案,要使用100行代码
时间: 2024-03-23 10:37:27 浏览: 26
下面是使用C语言编写的一个简易的爱心图案,代码共计100行:
```
#include <stdio.h>
#include <math.h>
int main()
{
int i, j;
double x, y, heart;
for(i=15; i>=-15; i--)
{
for(j=-30; j<=30; j++)
{
x = j * 0.04;
y = i * 0.1;
heart = pow((pow(x, 2) + pow(y, 2) - 1), 3) - pow(x, 2) * pow(y, 3);
if(heart <= 0.0)
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
```
运行程序后,程序会在屏幕上显示出一个简易的爱心图案。
相关问题
c 语言程序设计显示图案,C语言编程之一个最优美的图案
下面是一个常见的C语言程序设计显示图案的例子,它将显示一个菱形图案:
```
#include <stdio.h>
int main()
{
int i, j, n;
printf("请输入菱形的边长:");
scanf("%d", &n);
for(i=1; i<=n; i++)
{
for(j=1; j<=n-i; j++)
{
printf(" ");
}
for(j=1; j<=2*i-1; j++)
{
printf("*");
}
printf("\n");
}
for(i=n-1; i>=1; i--)
{
for(j=1; j<=n-i; j++)
{
printf(" ");
}
for(j=1; j<=2*i-1; j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
```
运行程序后,输入一个正整数作为菱形的边长,即可在屏幕上显示出一个优美的菱形图案。
单片机c语言设计奥运五环,用C语言程序来设计奥运五环图案
好的,以下是一个简单的单片机C语言程序,用于设计奥运五环图案:
```
#include <reg52.h> // 引入单片机头文件
// 定义五环颜色的RGB值
#define BLUE 0x01 // 蓝色
#define YELLOW 0x02 // 黄色
#define BLACK 0x03 // 黑色
#define GREEN 0x04 // 绿色
#define RED 0x05 // 红色
// 定义五个LED灯的引脚
sbit led1 = P0^0;
sbit led2 = P0^1;
sbit led3 = P0^2;
sbit led4 = P0^3;
sbit led5 = P0^4;
void delay(int time) // 定义延时函数
{
int i, j;
for(i = 0; i < time; i++)
{
for(j = 0; j < 120; j++);
}
}
void main()
{
while(1) // 无限循环
{
led1 = 1; // 亮蓝色灯
led2 = 0;
led3 = 0;
led4 = 0;
led5 = 0;
delay(1000); // 延时1秒钟
led1 = 0; // 亮黄色灯
led2 = 1;
led3 = 0;
led4 = 0;
led5 = 0;
delay(1000); // 延时1秒钟
led1 = 0; // 亮黑色灯
led2 = 0;
led3 = 1;
led4 = 0;
led5 = 0;
delay(1000); // 延时1秒钟
led1 = 0; // 亮绿色灯
led2 = 0;
led3 = 0;
led4 = 1;
led5 = 0;
delay(1000); // 延时1秒钟
led1 = 0; // 亮红色灯
led2 = 0;
led3 = 0;
led4 = 0;
led5 = 1;
delay(1000); // 延时1秒钟
}
}
```
这个程序使用了单片机的5个GPIO口,分别控制5个LED灯的亮灭,每隔1秒钟依次亮起不同颜色的LED灯,模拟奥运五环图案的效果。你可以根据需要修改程序来实现自己的需求。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://img-home.csdnimg.cn/images/20210720083646.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)