用c语言编写一个爱心,如何用C语言画一个心形

1,如何用C语言画一个心形百度C语言画一个“心形”~// x^2 = 1 - (y - x^(2/3))^2;#include #include int main() { double x, y; double e = 1/3.0, step = 0.025; for (y= 1.6; y > -1; y -= step * 6) { for (x= -1; x <= 1; x += step) { if (1 - pow(y-pow(pow(x, 2), e), 2) > x*x) printf("*"); else printf(" "); } printf("\n"); } return 0; }【用c语言编写一个爱心,如何用C语言画一个心形】
2,怎样用C语言编写心形心形应该不容易用数学函数表示,所以用楼上的方法更方便 , 不过这是在DOS字符下 , 如果在图形模式,或窗口程序中就可以输出很光滑的心了,不知楼主要哪种先自己在纸上画出你要的心形再按一楼的方法耐心的用printf()一行一行的编吧^_^printf(" ");printf(" ");printf("*"); .. 你算算要几个空格和*符` 一行行计好比较简单`写算法的话太复杂了`---------------------------------------------------------楼主是指: 整个心型用线连起来的?`这种要用算法把点充分排布才可以,C语言`大概上百行代码才能完成..int a=detect,b;float r,r=9;float n=10*3.14/180,x,y;int i;initgraph(&a,&b,"");circle(200,300,r);for(i=0;i<36;i++)y=300+r*sin(i*n);r=sqrt((x0-x)^2+(y0-y)^2);/*x0,y0为r圆上的一定点*/circle(x0,y0,r);}closegraph();可以自己设计一个循环.
3 , 如何用C语言循环做一个爱心要能动的#include<stdio.h>#include<string.h>int get_left_or_right_setp() static int current = 0; static int right = 1; if (1 == right) current++; } else current--; } if (10 == current) right = 0; } else if (0 == current) right = 1; } return current;}void kongge(int step_cnt) int i = 0; for (i = 0; i < step_cnt; i++) printf(" "); }}void clear_screen() //linux选这个 system("clear"); //win选这个 //system("cls");}void printf_love() int step_cnt = get_left_or_right_setp(); kongge(step_cnt); printf(" ** ** \n"); kongge(step_cnt); printf(" * * * * \n"); kongge(step_cnt); printf(" * * * \n"); kongge(step_cnt); printf(" * * \n"); kongge(step_cnt); printf(" * * \n"); kongge(step_cnt); printf(" * * \n"); kongge(step_cnt); printf(" * * \n"); kongge(step_cnt); printf(" * * \n"); kongge(step_cnt); printf(" * * \n"); kongge(step_cnt); printf(" * * \n"); kongge(step_cnt); printf(" * * \n"); kongge(step_cnt); printf(" * * \n"); kongge(step_cnt); printf(" * * \n"); kongge(step_cnt); printf(" * * \n"); kongge(step_cnt); printf(" * \n");}int main(void) while (1) clear_screen(); printf_love(); sleep(1); } return 0;}伪动态 靠清屏实现动态
4,怎样用C语言编写个爱心图象# include # include #include # define u 0.06 # define v 0.025 # define m 1.1 # define n 1.2 int main(void) { float x, y; float m, n; char a[6600]; for ( y=2; y>=-2; y-=u ) { for ( x=-1.2; x<=1.2; x+=v) { if ( ( ( (x*x + y*y - 1)*(x*x + y*y - 1)*(x*x + y*y - 1) - x*x*y*y*y ) <= 0 ) ) strcat(a,"*"); else strcat(a," "); } strcat(a,"\n"); } strcat(a,"\0"); printf("%s\n",a); getchar(); return 0; }创建一个心形图案需要的最长字符串,充分利用printf函数输出字符串的丰富控制功能,按心形图案每行所需长度和位置,对所创建的字符串进行截断并在所需位置上输出,最后在屏幕上形成由字符组成的心形图案 。//#include "stdafx.h"//If the vc++6.0, with this line.#include "stdio.h"int main(void) char a[]="I love you I love you I love you I l"; printf("\n\n\n"); printf("%*.*s\n",58,21,"_*=_ _=*_"); printf("%*.*s\n",61,25,"I love yo u I love!"); printf("%*.*s\n",63,29,"I love you I l ove you I love"); printf("%*.*s\n",65,33,a);//在屏幕第65个字符处开始输出字符串a的前33个字符,其他各句意义相同 printf("%*.*s\n",66,35,a); printf("%*.*s\n",66,35,a); printf("%*.*s\n",65,33,a); printf("%*.*s\n",64,31,a); printf("%*.*s\n",63,29,a); printf("%*.*s\n",61,25,a); printf("%*.*s\n",59,21,a); printf("%*.*s\n",57,17,a); printf("%*.*s\n",55,13,a); printf("%*.*s\n",53,9,a); printf("%*.*s\n",51,5,a); printf("%*.*s\n",50,3,a); printf("%*.*s\n",49,1,a); return 0;}双层循环就可以了不过最简单的楼上的兄弟已经说了倒心:#include<stdio.h>#include<math.h>void main()int a,b,c; for(a=1;a<=6;a++)printf(" ");for(c=1;c<=2*a-1;c++)printf("\3");else printf(" ");}printf("\n"); }}双心:#include<stdio.h>#include<math.h>void main()int a,b,c; for(a=1;a<=6;a++)for(b=1;b<=6-a;b++)printf(" ");for(c=1;c<=2*a-1;c++)if(a<5&&(c==1||c==2*a-1)||(a==5&&(c==2||c==5||c==8))||a==6&&(c==4||c==5||c==7||c==8))printf("\3");else printf(" ");}printf("\n");} for(a=1;a<=6;a++)for(b=1;b<=a;b++)printf(" ");for(c=1;c<=11-2*a;c++)if(a>1&&(c==1||c==11-2*a)||a==1&&(c==2||c==5||c==8))printf("\3");else printf(" ");} printf("\n"); }}正心:#include<stdio.h>#include<math.h>void main()int a,b,c; printf("\3\3 \3\3\n"); for(a=1;a<=6;a++)for(b=1;b<=a;b++)printf(" ");for(c=1;c<=11-2*a;c++)if(a>1&&(c==1||c==11-2*a)||a==1&&(c==2||c==5||c==8))printf("\3");else printf(" ");} printf("\n"); }}

    推荐阅读