输出心形图案

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;
}
相关推荐
樱木Plus2 天前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++
blasit4 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_5 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星5 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛7 天前
delete又未完全delete
c++
端平入洛8 天前
auto有时不auto
c++
哇哈哈20219 天前
信号量和信号
linux·c++
多恩Stone9 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
蜡笔小马9 天前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
超级大福宝9 天前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode