C/java implements love

Tanabata is coming! It's time to show the romance exclusive to programmers!

The legend of the Qixi Festival is believed to be familiar to most people, because there are countless film and television works related to the Qixi Festival, which are deeply rooted in the hearts of the people, and the legend of the Cowherd and the Weaver Girl on the Qixi Festival itself is one of the four major folk legends in my country. What are the stories related to Qixi Festival?
insert image description here
  The legend we are most familiar with is this. According to legend, the cowherd’s parents died young, and he was not welcomed by his elder brother and sister-in-law when he was young. A woman who can be called a fairy, that is, Zhinv, is the so-called love at first sight. Cowherd fell into unrequited love, and the old cow saw that Cowherd seemed to be troubled, so he appeared and gave him a plan, how to capture him Zhinu's heart.

One day, the fairy was bathing in the river. Seeing this, the Cowherd decisively took away the clothes of the Weaver Girl. Naturally, she panicked and begged the Cowherd to return the clothes to her, but of course the Cowherd refused I gave her the clothes, so I said, "If you are willing to be my wife, then this clothes will be given to you", and Zhinu agreed, because she came here for the cowherd at the beginning, and now they are in agreement, so simply It's also suitable to be together. The married life was very happy, and even gave birth to a son and a daughter, until the old cow passed away when he was too old. The couple were very sad, but the old cow told the cowherd to keep its hide , put on for help in times of emergency. After the old cow died, the couple reluctantly peeled off the cowhide and buried the cow on the hillside.

But the good days soon came the nightmare, when the Jade Emperor and the Queen Mother found out that the Weaver Girl and the Cowherd were married, they sent people down to capture the Weaver Girl. The Cowherd didn't see the Weaver Girl when he came home, so he guessed that it was someone from the Heavenly Court, so he remembered the old cow's advice, put on the cowhide in a hurry, carried two children and flew up.

insert image description here

Seeing that she was about to catch up, the Queen Mother was anxious, she pulled out the golden hairpin on her head and swiped towards the Milky Way. From then on, the Cowherd and the Weaver Girl could only look at each other across the river with tears in their eyes forever. The Jade Emperor and the Queen Mother couldn't resist their sincere feelings and allowed them to meet once a year on July 7th. I want to fly to the sky and build a magpie bridge for the Cowherd and the Weaver Girl to meet in the Milky Way.

After this story is finished, I will use C and Java to realize the romantic love belonging to programmers.

C language

code show as below:

#include<stdio.h>
#include<Windows.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;
			putchar(a * a * a - x * x * y * y * y <= 0.0 ? '*' : ' ');
		}
		system("color 0c");
		putchar('\n');
	}
	printf("                         送给xxx!");//这里xxx可以改成你对象名字
	printf("\n\n\n");
	return 0;
}

operation result:
insert image description here

Java

Realize hollow love

code show as below:

    public  static  void heart1(){
    
    
        float x,y,a;
        for(y=1.3f;y>-1.1f;y-=0.06f){
    
       //这里的参数皆可以调,条件就是看着顺眼
            for(x=-1.2f;x<=1.2f;x+=0.025f){
    
    
                a=x*x+y*y-1;
                System.out.print(a*a*a-x*x*y*y*y<=0.0f?' ':'$');
            }
            System.out.println();
        }
    }

operation result:
insert image description here

To achieve solid love:

code show as below:

public static  void heart2(){
    
    
        double x,y,a;
        char s[]=new char[]{
    
    'I',' ','l','o','v','e',' ','y','o','u','!'};
        int index=0;
        for(y=1.3f;y>-1.1f;y-=0.06f){
    
    
            index=0;
            for(x=-1.1f;x<=1.1f;x+=0.025f){
    
    
                double result=x*x+pow((5.0*y/4.0-sqrt(abs(x))),2);
                if(result<=1){
    
    
                    System.out.print((s[index]));
                    index=(index+1)%11;
                }
                else{
    
    
                    System.out.print(' ');
                }
            }
            System.out.println(" ");
        }
    }

operation result:
insert image description here

Finally, I wish all lovers get married! ! ! !

Guess you like

Origin blog.csdn.net/weixin_56935264/article/details/126153590