English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 answers

Hi,

The heart consists of two parts...
1) Top Part
2) Bottom Part

The Top Part has two Semi-Circles next to each other
The bottom part has an upside down triangle. (Equilateral Triangle)

Now, to draw the triangle is relatively simple.
void printEmpty(int n) {
int i;
for(i=0;i printf(" ");
}
int main()
{
int i,j;
int num;
for(i=0;i<20;i++) {
printEmpty(i);
for(j=0;j<(20-2*i);j++) {
printf("X");
}
printEmpty(i);
printf("\n");
}
return 0;
}

That will draw a triangle I think :x I didn't test it, but makes sence to me. You add an empty char at the begninng and at the end. While reducing it from the length of iteration in the inner loop.

Now your task is to try doing the circle. Which wont be hard. My hint will be, try to find the mathematical equation to calculate the arc.

Good Luck

2006-10-07 03:34:59 · answer #1 · answered by ? 6 · 0 0

Create an array of 0's an 1's that will create the shape of the heart, something similar to:

0000000000000000000
0000111000001110000
0001000100010001000
0010000010100000100
0010000001000000100
0001000000000001000
0000100000000010000
0000010000000100000
0000001000001000000
0000000100010000000
0000000010100000000
0000000001000000000
0000000000000000000

Next, create a loop that prints each "line" in the array by placing a blank space where there's a 0, and an X (or whatever) where there's a 1.

You can then change the picture at any time by simply changing the array.

2006-10-07 14:08:58 · answer #2 · answered by addtheninth 2 · 0 1

fedest.com, questions and answers