520谐音“我爱你”于是这一天也变成了表白日在“520”这个特殊的日子也请收下程序员们用C语言带来的“特殊告白”,用C语言代码编程爱心模样。
	 
	
	
 
	源码如下:
 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h>
#include <windows.h> 
#include <time.h>
const float U = 0.1; 
const float V = 0.053; 
char word[] = "qwertyuiopasdfghjklzxcvbnm1234567890!@#$%^&*()_+=";
void SetColor(unsigned short fc, unsigned short bc) { 
  HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); 
  SetConsoleTextAttribute(hCon, (fc % 16) | (bc % 16 * 16)); 
} 
int if_in_heart(float x, float y) 
{ 
  float t = (x * x + y * y - 1);
  t = t * t * t;
   return ((t - x * x * y * y * y) <= 0); 
} 
void print_love()
{ 
  int slen = strlen(word);
   int color = rand()%255;
   color = color % 16 ? color : 1;
   SetColor(color, 0);
   int f = rand()%slen;
   putchar(word[f]); 
} 
void draw_heart() { 
   int i; 
  float x, y; 
   for (y = 1.3; y >= -1.1; y -= U) { 
     for (x = -2; x < 1.4; x += V) { 
        if (if_in_heart(x, y) )  {
            print_love();
      } else {
           printf(" ");
       }
        
    } 
    printf("\n"); 
  } 
}
    
int main() 
{ 
  SetConsoleCP(437);
  SetConsoleOutputCP(437);
  srand(time(NULL)); 
  draw_heart(); 
  getchar();
  return 0;
}
说明:本程序使用 dev c++ 编译运行。理论上 其他编译器应该也是能正常编译的。
	
如果不喜欢这种混乱字母的形式,只需要改变 第 9 行 即可!
比如把第 9 行改为:
char word[] = "*";
效果如下:
	 
 
第9行如果改成:
	
char word[] = "+";效果如下:
	
	 
 
以上就是“520了,用C语言编程画了一个爱心表白(用c语言编写一个爱心的程序)”的详细内容,想要了解更多C语言教程欢迎持续关注编程学习网
扫码二维码 获取免费视频学习资料

- 本文固定链接: http://phpxs.com/post/9477/
- 转载请注明:转载必须在正文中标注并保留原文链接
- 扫码: 扫上方二维码获取免费视频资料
					查 看2022高级编程视频教程免费获取
				
			 
			








