Imprimir patrón de corazón en C

¿Cómo imprimir debajo del patrón de corazón en C?

    AAAAAAA        AAAAAA
   AAAAAAAAA      AAAAAAAA
  AAAAAAAAAAA    AAAAAAAAAA
 AAAAAAAAAAAAA  AAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBB
 BBBBBBBBBBBBBBBBBBBBBBBBBBB
  BBBBBBBBBBBBBBBBBBBBBBBBB
   BBBBBBBBBBBBBBBBBBBBBBB
    BBBBBBBBBBBBBBBBBBBBB
     BBBBBBBBBBBBBBBBBBB
      BBBBBBBBBBBBBBBBB
       BBBBBBBBBBBBBBB
        BBBBBBBBBBBBB
         BBBBBBBBBBB
          BBBBBBBBB
           BBBBBBB
            BBBBB
             BBB
              B

HEART PRINITNG

C++

// C++ code to print a HEART Shape
#include<iostream>
using namespace std;
   
int main()
{
    // HERE, we have set the size of Heart, size = 15
    int a, b, size = 15;
   
    /* FOR THE APEX OF HEART */
    for (a = size/2; a <= size; a = a+2)
    {
        // FOR SPACE BEFORE PEAK-1 : PART 1
        for (b = 1; b < size-a; b = b+2)        
            cout<<" ";
   
        // FOR PRINTING PEAK-1 : PART 2
        for (b = 1; b <= a; b++)
            cout<<"A";
    
        // FOR SPACE B/W PEAK-1 AND PEAK-2 : PART 3
        for (b = 1; b <= size-a; b++)
            cout<<" ";
           
        // FOR PRINTING PEAK-2 : PART 4
        for (b = 1; b <= a-1; b++)
            cout<<"A";
   
        cout<<endl;
    }
   
    /*FOR THE BASE OF HEART ie. THE INVERTED TRIANGLE */
   
    for (a = size; a >= 0; a--)
    {
        // FOR SPACE BEFORE THE INVERTED TRIANGLE : PART 5 
        for (b = a; b < size; b++)
            cout<<" ";
   
        // FOR PRINTING THE BASE OF TRIANGLE : PART 6
        for (b = 1; b <= ((a * 2) - 1); b++)
            cout<<"B";
   
        cout<<endl;  
    }
}
// This code is contributed by Kunal Mali.

C

// C code to print a HEART Shape
#include<stdio.h>
 
int main()
{
    // HERE, we have set the size of Heart, size = 10
    int a, b, size = 15;
 
    /* FOR THE APEX OF HEART */
    for (a = size/2; a <= size; a = a+2)
    {
        // FOR SPACE BEFORE PEAK-1 : PART 1
        for (b = 1; b < size-a; b = b+2)       
            printf(" ");
 
        // FOR PRINTING PEAK-1 : PART 2
        for (b = 1; b <= a; b++)
            printf("A");
  
        // FOR SPACE B/W PEAK-1 AND PEAK-2 : PART 3
        for (b = 1; b <= size-a; b++)
            printf(" ");
         
        // FOR PRINTING PEAK-2 : PART 4
        for (b = 1; b <= a-1; b++)
            printf("A");
 
        printf("\n");
    }
 
    /*FOR THE BASE OF HEART ie. THE INVERTED TRIANGLE */
 
    for (a = size; a >= 0; a--)
    {
        // FOR SPACE BEFORE THE INVERTED TRIANGLE : PART 5
        for (b = a; b < size; b++)
            printf(" ");
 
        // FOR PRINTING THE BASE OF TRIANGLE : PART 6
        for (b = 1; b <= ((a * 2) - 1); b++)
            printf("B");
 
        printf("\n"); 
    }
}

Java

// Java code to print a HEART Shape
 
class GFG {
     
public static void main(String arg[]) {
     
    // HERE, we have set the size of Heart, size = 10
    int a, b, size = 15;
 
    /* FOR THE APEX OF HEART */
    for (a = size / 2; a <= size; a = a + 2) {
         
    // FOR SPACE BEFORE PEAK-1 : PART 1
    for (b = 1; b < size - a; b = b + 2)
        System.out.print(" ");
 
    // FOR PRINTING PEAK-1 : PART 2
    for (b = 1; b <= a; b++)
        System.out.print("A");
 
    // FOR SPACE B/W PEAK-1 AND PEAK-2 : PART 3
    for (b = 1; b <= size - a; b++)
        System.out.print(" ");
 
    // FOR PRINTING PEAK-2 : PART 4
    for (b = 1; b <= a - 1; b++)
        System.out.print("A");
 
    System.out.print("\n");
    }
 
    /*FOR THE BASE OF HEART ie. THE INVERTED TRIANGLE */
 
    for (a = size; a >= 0; a--) {
         
    // FOR SPACE BEFORE THE INVERTED TRIANGLE : PART 5
    for (b = a; b < size; b++)
        System.out.print(" ");
 
    // FOR PRINTING THE BASE OF TRIANGLE : PART 6
    for (b = 1; b <= ((a * 2) - 1); b++)
        System.out.print("B");
 
    System.out.print("\n");
    }
}
}
 
// This code is contributed by Anant Agarwal.

Python3

# Python 3 code to print a HEART Shape
 
# HERE, we have set the size of Heart,
# size = 10
size = 15
 
# FOR THE APEX OF HEART
for a in range(int(size / 2), size + 1, 2):
     
    # FOR SPACE BEFORE PEAK-1 : PART 1
    for b in range(1, size - a, 2):
        print(" ", end = "")
 
    # FOR PRINTING PEAK-1 : PART 2
    for b in range(1, a + 1):
        print("A",end="")
 
    # FOR SPACE B/W PEAK-1 AND PEAK-2 :
    # PART 3
    for b in range(1, (size - a) + 1):
        print(" ", end = "")
         
    # FOR PRINTING PEAK-2 : PART 4
    for b in range(1, a):
        print("A", end = "")
 
    print("")
     
 
# FOR THE BASE OF HEART ie. THE INVERTED
# TRIANGLE
for a in range(size, -1, -1):
     
# FOR SPACE BEFORE THE INVERTED TRIANGLE:
# PART 5
    for b in range(a, size):
        print(" ", end = "")
         
    # FOR PRINTING THE BASE OF TRIANGLE:
    # PART 6
    for b in range(1, (a * 2)):
        print("B", end = "")
    print("")
     
# This code is contributed by Smitha.

C#

// Java code to print a HEART Shape
using System;
 
class GFG {
     
public static void Main() {
     
    // HERE, we have set the size of Heart, size = 10
    int a, b, size = 15;
 
    /* FOR THE APEX OF HEART */
    for (a = size / 2; a <= size; a = a + 2) {
         
    // FOR SPACE BEFORE PEAK-1 : PART 1
    for (b = 1; b < size - a; b = b + 2)
        Console.Write(" ");
 
    // FOR PRINTING PEAK-1 : PART 2
    for (b = 1; b <= a; b++)
        Console.Write("A");
 
    // FOR SPACE B/W PEAK-1 AND PEAK-2 : PART 3
    for (b = 1; b <= size - a; b++)
        Console.Write(" ");
 
    // FOR PRINTING PEAK-2 : PART 4
    for (b = 1; b <= a - 1; b++)
        Console.Write("A");
 
    Console.WriteLine();
    }
 
    /*FOR THE BASE OF HEART ie. THE INVERTED TRIANGLE */
 
    for (a = size; a >= 0; a--) {
         
    // FOR SPACE BEFORE THE INVERTED TRIANGLE : PART 5
    for (b = a; b < size; b++)
        Console.Write(" ");
 
    // FOR PRINTING THE BASE OF TRIANGLE : PART 6
    for (b = 1; b <= ((a * 2) - 1); b++)
        Console.Write("B");
 
    Console.WriteLine("");
    }
}
}
 
// This code is contributed by vt_m.

PHP

<?php
 
// php code to print a HEART Shape
 
    // HERE, we have set the size
    // of Heart, size = 10
    $size = 15;
 
    // FOR THE APEX OF HEART
    for ($a = floor($size / 2); $a <= $size;
                                $a = $a + 2)
    {
         
        // FOR SPACE BEFORE PEAK-1 : PART 1
        for ($b = 1; $b < $size-$a;
                      $b = $b + 2)
            printf(" ");
 
        // FOR PRINTING PEAK-1 : PART 2
        for ($b = 1; $b <= $a; $b++)
            printf("A");
 
        // FOR SPACE B/W PEAK-1 AND PEAK-2 : PART 3
        for ($b = 1; $b <= $size-$a; $b++)
            printf(" ");
         
        // FOR PRINTING PEAK-2 : PART 4
        for ($b = 1; $b <= $a - 1; $b++)
            printf("A");
 
        printf("\n");
    }
 
    // FOR THE BASE OF HEART ie.
    // THE INVERTED TRIANGLE
    for ($a = $size; $a >= 0; $a--)
    {
         
        // FOR SPACE BEFORE THE
        // INVERTED TRIANGLE : PART 5
        for ($b = $a; $b < $size; $b++)
            printf(" ");
 
        // FOR PRINTING THE BASE
        // OF TRIANGLE : PART 6
        for ($b = 1; $b <= (($a * 2) - 1); $b++)
            printf("B");
 
        printf("\n");
    }
 
// This code is contributed by mits
 
?>

Javascript

<script>
 
// javascript code to print a HEART Shape  
 
     
    // HERE, we have set the size of Heart, size = 10
    var a, b, size = 15;
 
    /* FOR THE APEX OF HEART */
    for (a = parseInt(size / 2); a <= size; a = a + 2) {
         
    // FOR SPACE BEFORE PEAK-1 : PART 1
    for (b = 1; b < size - a; b = b + 2)
        document.write(" ");
 
    // FOR PRINTING PEAK-1 : PART 2
    for (b = 1; b <= a; b++)
        document.write("A");
 
    // FOR SPACE B/W PEAK-1 AND PEAK-2 : PART 3
    for (b = 1; b <= size - a; b++)
        document.write(" ");
 
    // FOR PRINTING PEAK-2 : PART 4
    for (b = 1; b <= a - 1; b++)
        document.write("A");
 
    document.write("<br>");
    }
 
    /*FOR THE BASE OF HEART ie. THE INVERTED TRIANGLE */
 
    for (a = size; a >= 0; a--) {
         
    // FOR SPACE BEFORE THE INVERTED TRIANGLE : PART 5
    for (b = a; b < size; b++)
        document.write(" ");
 
    // FOR PRINTING THE BASE OF TRIANGLE : PART 6
    for (b = 1; b <= ((a * 2) - 1); b++)
        document.write("B");
 
    document.write("<br>");
    }
 
 
 
// This code contributed by Princi Singh
</script>

Producción : 

    AAAAAAA        AAAAAA
   AAAAAAAAA      AAAAAAAA
  AAAAAAAAAAA    AAAAAAAAAA
 AAAAAAAAAAAAA  AAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBB
 BBBBBBBBBBBBBBBBBBBBBBBBBBB
  BBBBBBBBBBBBBBBBBBBBBBBBB
   BBBBBBBBBBBBBBBBBBBBBBB
    BBBBBBBBBBBBBBBBBBBBB
     BBBBBBBBBBBBBBBBBBB
      BBBBBBBBBBBBBBBBB
       BBBBBBBBBBBBBBB
        BBBBBBBBBBBBB
         BBBBBBBBBBB
          BBBBBBBBB
           BBBBBBB
            BBBBB
             BBB
              B

Este artículo es aportado por Mohit Gupta 🙂 . Si te gusta GeeksforGeeks y te gustaría contribuir, también puedes escribir un artículo usando write.geeksforgeeks.org o enviar tu artículo por correo a review-team@geeksforgeeks.org. Vea su artículo que aparece en la página principal de GeeksforGeeks y ayude a otros Geeks.
Escriba comentarios si encuentra algo incorrecto o si desea compartir más información sobre el tema tratado anteriormente. 

Publicación traducida automáticamente

Artículo escrito por GeeksforGeeks-1 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *