Advertisement
nghiahsgs

Untitled

Sep 17th, 2018
19,244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1.  
  2. // C code to print a HEART Shape
  3. #include<stdio.h>
  4.  
  5. int main()
  6. {
  7.     // HERE, we have set the size of Heart, size = 10
  8.     int a, b, size = 15;
  9.  
  10.     /* FOR THE APEX OF HEART */
  11.     for (a = size/2; a <= size; a = a+2)
  12.     {
  13.         // FOR SPACE BEFORE PEAK-1 : PART 1
  14.         for (b = 1; b < size-a; b = b+2)        
  15.             printf(" ");
  16.  
  17.         // FOR PRINTING PEAK-1 : PART 2
  18.         for (b = 1; b <= a; b++)
  19.             printf("A");
  20.    
  21.         // FOR SPACE B/W PEAK-1 AND PEAK-2 : PART 3
  22.         for (b = 1; b <= size-a; b++)
  23.             printf(" ");
  24.          
  25.         // FOR PRINTING PEAK-2 : PART 4
  26.         for (b = 1; b <= a-1; b++)
  27.             printf("A");
  28.  
  29.         printf("\n");
  30.     }
  31.  
  32.     /*FOR THE BASE OF HEART ie. THE INVERTED TRIANGLE */
  33.  
  34.     for (a = size; a >= 0; a--)
  35.     {
  36.         // FOR SPACE BEFORE THE INVERTED TRIANGLE : PART 5  
  37.         for (b = a; b < size; b++)
  38.             printf(" ");
  39.  
  40.         // FOR PRINTING THE BASE OF TRIANGLE : PART 6
  41.         for (b = 1; b <= ((a * 2) - 1); b++)
  42.             printf("B");
  43.  
  44.         printf("\n");  
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement