输出心形图案

cpp 复制代码
#include<stdio.h>
#include<stdlib.h>
#include<math.h> 
int main()
{	float x,y,a;	
	for(y=1.5;y>-1.5;y-=0.1)	
	{		
		for(x=-1.5;x<1.5;x+=0.05)		
		{			
			if((pow(x,2)+pow(5.0*y/4.0-sqrt(fabs(x)),2))<=1)								putchar('*');			
			else				
				putchar(' ');		
		}		
		system("color 0c");		
		putchar('\n'); 
	}
		return 0;
}
cpp 复制代码
#include<stdio.h>
#include<stdlib.h>
int main()
{	float x,y,a;	
	for(y=1.5;y>-1.5;y-=0.1)	
	{		
		for(x=-1.5;x<1.5;x+=0.05)		
		{			
			a=x*x+y*y-1;			
			if(a*a*a-x*x*y*y*y<=0.0)				
				putchar('*');			
			else				
				putchar(' ');		
		}		
		system("color 0c");		
		putchar('\n'); 
	}
		return 0;
}
cpp 复制代码
#include<stdio.h>
#include<stdlib.h>
#include<math.h> 
int main()
{	float x,y,a;	
	for(y=1.5;y>-1.5;y-=0.1)	
	{		
		for(x=-1.5;x<1.5;x+=0.05)		
		{			
			if(pow((x*x+y*y-1),3)-pow(x,2)*pow(y,3)<=0.0)				
				putchar('*');			
			else				
				putchar(' ');		
		}		
		system("color 0c");		
		putchar('\n'); 
	}
		return 0;
}

用 system("color **")可设置背景和前景,颜色之间也可混合使用

for循环:

cpp 复制代码
#include<stdio.h> 
#include<stdlib.h>
int main()
{
	int i,j;
	//开头空5行 
	for(i=1;i<=5;i++)
		printf("\n");
	//前三行 
	for(i=1;i<=3;i++)
	{
		for(j=1;j<=17-2*i;j++)
			printf(" ");
		for(j=1;j<=4*i+1 ;j++)
			printf("*");
		for(j=1;j<=13-4*i;j++)
			printf(" ");
		for(j=1;j<=4*i+1 ;j++)
			printf("*");
		printf("\n");	
	}
	//中间3行输出29颗星 
	for(i=1;i<=3;i++)
	{
		for(j=1;j<=10;j++)
			printf(" ");
		for(j=1;j<=29;j++)
			printf("*");
		printf("\n");
	}
	//下7行 倒三角造型 
	for(i=1;i<=7;i++)	
	{
		
		for(j=1;j<=2*i-1+10;j++)
			printf(" ");
		for(j=1;j<=31-4*i;j++)
			printf("*");
		printf("\n");
	}
	//图案最后一行一颗星 
	for(i=1;i<=14+10;i++)
		printf(" ");
	printf("*");
	//下方空5行 
	for(i=1;i<=5;i++)
		printf("\n");
	system("color 0c"); 	         //修改系统色,前景色为c红色,背景色为0黑色。 
	return 0;
}
相关推荐
劲镝丶1 小时前
malloc概述
c语言·开发语言·c++
努力努力再努力wz2 小时前
【C++进阶系列】:万字详解红黑树(附模拟实现的源码)
java·linux·运维·c语言·开发语言·c++
cccyi72 小时前
C/C++类型转换
c++
枫fengw2 小时前
9.8 C++
开发语言·c++
JCBP_3 小时前
QT(3)
开发语言·汇编·c++·qt·算法
XFF不秃头3 小时前
力扣刷题笔记-三数之和
c++·笔记·算法·leetcode
Pafey3 小时前
VS2022 + Qt5.9 中文乱码/项目设置utf-8编码
c++·qt·中文乱码
minji...3 小时前
C++ STL之list的使用
开发语言·c++
青草地溪水旁4 小时前
23 种设计模式
开发语言·c++·设计模式
Want5954 小时前
C/C++圣诞树②
c语言·c++·算法