Home > Back-end >  C language implementation print out the heart, do a beginner's artifact.
C language implementation print out the heart, do a beginner's artifact.

Time:01-27


Source:

#include//the header file
Int main ()//main function entry
{
Printf (" * * * * * * * * \ n ");//print the first line
Printf (" * * * * * * * * * * * * * * * * * * \ n ");//print the second line
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");//print the third line
int i,j;//define variables
for(i=0; i<3; I++)//print 4-6 lines, a total of 3 lines, so I less than 3
{
for(j=0; J<29. J++)//limiting the number of each output *
{
Printf (" * ");//only print * these three lines, there is no space output
}
printf("\n");//print out a line to line feed
}
for(i=0; i<7. I++)//print 7 to 13 line, a total of 7 lines, so I less than 7
{
for(j=0; J<2 * (I + 1) - 1; J++)//the for loop and the following for coordinate
{
Printf (" ");//print space
}
for(j=0; J<27 - I * 4; J++)//readers can into several number to find conditions
{
Printf (" * ");//print *
}
printf("\n");
}
for(i=0; i<14. I++)//print the last line *
{
Printf (" ");//print space
}
Printf (" * \ n ");//print *
return 0;
}



Do the second source demo:

#include//the header file
#include//function to refer to pow
Int main ()//main function entry
{
Float y, x, z;//floating-point variables
Printf (" only when thinking of you \ n ");//hint statements
Want to embrace you fall down printf (" \ n ");//hint statements
Printf (" happy to pounce on you \ n ");//hint statements
Printf (" excitement want to kiss you \ n ");//hint statements
Printf (" everything is in these three words signature didn't sign \ n ");//hint statements
printf("\n");//line breaks
For (double y=2.5; Y & gt;=1.6; Y=y - 0.2)
{
For (double x=3; X & lt;=4.8; X=x + 0.1)
{
//the following is a ternary operation, the reader, please look at carefully, | | this is or
((pow (x) * x + y * y - 1, 3) & lt;=3.6 * x * x * * * y y y
| | (x> 2.4 & amp; & x<2.1 & amp; & Y<1.5 & amp; & Y> 1)
| | (((x<2.5 & amp; & X> 2.2) | | (x> 3.4 & amp; & x<3.7) & amp; & Y> 1 & amp; & Y<1.5)
| | (y> 1 & amp; & Y<0.6 & amp; & x<3.7 & amp; & X> 2.2))? Printf (" * ") : printf (" ");
}
printf("\n");//line breaks
}
getchar();
return 0;//function returns a value of 0
}

Problem: the code has a bug, please help to have a look, if you can, help explain the meaning of the code, by the way, thank you very much,
Of the new small white, a face of fan mang
-
O answer -

CodePudding user response:

A suggestion: loop variables with integer, because the floating-point number, there will be a small error can lead to cycles with different expected,
For example,
 
for (int i=0; i<21. I++)
{
Double y=2.5 * 0.2 I;
.
}
  • Related