Programa para imprimir Patrón de Cometa

La tarea dada es dibujar un patrón KITE usando ‘$’ 
Ejemplo: 
 

Output:
       $
      $$$
     $$$$$
    $$$$$$$
   $$$$$$$$$
    $$$$$$$
     $$$$$
      $$$
       $
      $$$
     $$$$$

A continuación se muestra el código para implementar el problema anterior:
Programa: 
 

C++

// C++ Program to print Kite Pattern
#include <bits/stdc++.h>
#include <stdlib.h>
 
using namespace std;
int main()
{
 
    int i, j, k, sp, space = 4;
    char prt = '$';
 
    for (i = 1; i <= 5; i++)
    {
 
        // For printing the space
        for (sp = space; sp >= 1; sp--)
        {
            cout << " ";
        }
 
        // For printing the $
        for (j = 1; j <= i; j++)
        {
            cout << prt;
        }
 
        for (k = 1; k <= (i - 1); k++)
        {
            if (i == 1)
            {
                continue;
            }
 
            cout << prt;
        }
        cout << "\n";
        space--;
    }
 
    space = 1;
 
    for (i = 4; i >= 1; i--)
    {
        for (sp = space; sp >= 1; sp--)
        {
            cout << " ";
        }
 
        for (j = 1; j <= i; j++)
        {
            cout << prt;
        }
 
        for (k = 1; k <= (i - 1); k++)
        {
            cout << prt;
        }
 
        space++;
        cout << "\n";
    }
 
    space = 3;
 
    for (i = 2; i <= 5; i++)
    {
        if ((i % 2) != 0)
        {
            for (sp = space; sp >= 1; sp--)
            {
                cout << " ";
            }
 
            for (j = 1; j <= i; j++)
            {
                cout << prt;
            }
        }
 
        if ((i % 2) != 0)
        {
            cout << "\n";
            space--;
        }
    }
 
    return 0;
}
 
// This code is contributed
// by Akanksha Rai(Abby_akku)

C

// C Program to print Kite Pattern
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
 
    int i, j, k, sp, space = 4;
    char prt = '$';
 
    for (i = 1; i <= 5; i++) {
 
        // For printing the space
        for (sp = space; sp >= 1; sp--) {
            printf(" ");
        }
 
        // For printing the $
        for (j = 1; j <= i; j++) {
            printf("%c", prt);
        }
 
        for (k = 1; k <= (i - 1); k++) {
            if (i == 1) {
                continue;
            }
 
            printf("%c", prt);
        }
        printf("\n");
        space--;
    }
 
    space = 1;
 
    for (i = 4; i >= 1; i--) {
        for (sp = space; sp >= 1; sp--) {
            printf(" ");
        }
 
        for (j = 1; j <= i; j++) {
            printf("%c", prt);
        }
 
        for (k = 1; k <= (i - 1); k++) {
            printf("%c", prt);
        }
 
        space++;
        printf("\n");
    }
 
    space = 3;
 
    for (i = 2; i <= 5; i++) {
        if ((i % 2) != 0) {
            for (sp = space; sp >= 1; sp--) {
                printf(" ");
            }
 
            for (j = 1; j <= i; j++) {
                printf("%c", prt);
            }
        }
 
        if ((i % 2) != 0) {
            printf("\n");
            space--;
        }
    }
 
    return 0;
}

Java

// Java Program to print Kite Pattern
import java.io.*;
 
class GFG
{
public static void main(String[] args)
{
 
    int i, j, k, sp, space = 4;
    char prt = '$';
 
    for (i = 1; i <= 5; i++)
    {
 
        // For printing the space
        for (sp = space; sp >= 1; sp--)
        {
            System.out.print(" ");
        }
 
        // For printing the $
        for (j = 1; j <= i; j++)
        {
            System.out.print(prt);
        }
 
        for (k = 1; k <= (i - 1); k++)
        {
            if (i == 1)
            {
                continue;
            }
 
            System.out.print(prt);
        }
        System.out.println();
        space--;
    }
 
    space = 1;
 
    for (i = 4; i >= 1; i--)
    {
        for (sp = space; sp >= 1; sp--)
        {
            System.out.print(" ");
        }
 
        for (j = 1; j <= i; j++)
        {
          System.out.print(prt);
        }
 
        for (k = 1; k <= (i - 1); k++)
        {
            System.out.print(prt);
        }
 
        space++;
        System.out.println();
    }
 
    space = 3;
 
    for (i = 2; i <= 5; i++)
    {
        if ((i % 2) != 0)
        {
            for (sp = space; sp >= 1; sp--)
            {
                System.out.print(" ");
            }
 
            for (j = 1; j <= i; j++)
            {
                System.out.print(prt);
            }
        }
 
        if ((i % 2) != 0)
        {
            System.out.println();
            space--;
        }
    }
}
}
 
// This code is contributed by inder_verma..

Python3

# Python3 Program to print Kite Pattern
if __name__ == '__main__':
 
    space = 4
    prt = '$'
 
    for i in range(1, 6):
 
        # For printing the space
        for sp in range(space, 0, -1):
            print(end = " ")
 
        # For printing the $
        for j in range(1, i + 1):
            print(prt, end = "")
 
        for k in range(1, i):
         
            if (i == 1):
             
                continue
             
            print(prt, end = "")
 
        print()
        space -= 1
     
    space = 1
 
    for i in range(4, 0, -1):
 
        for sp in range(space, 0, -1):
            print(end = " ")
 
        for j in range(1, i + 1):
            print(prt, end = "")
 
        for k in range(1, i):
            print(prt, end = "")
 
        space += 1
        print()
 
    space = 3
 
    for i in range(2, 6):
 
        if ((i % 2) != 0):
         
            for sp in range(space, 0, -1):
                print(" ", end = "")
 
            for j in range(1, i + 1):
                print(prt, end = "")
 
        if ((i % 2) != 0):
            print()
            space -= 1
 
# This code is contributed by
# mohit kumar 29

C#

// C# Program to print Kite Pattern
using System;
 
class GFG
{
public static void Main()
{
 
    int i, j, k, sp, space = 4;
    char prt = '$';
 
    for (i = 1; i <= 5; i++)
    {
 
        // For printing the space
        for (sp = space; sp >= 1; sp--)
        {
            Console.Write(" ");
        }
 
        // For printing the $
        for (j = 1; j <= i; j++)
        {
            Console.Write(prt);
        }
 
        for (k = 1; k <= (i - 1); k++)
        {
            if (i == 1)
            {
                continue;
            }
 
            Console.Write(prt);
        }
        Console.WriteLine();
        space--;
    }
 
    space = 1;
 
    for (i = 4; i >= 1; i--)
    {
        for (sp = space; sp >= 1; sp--)
        {
            Console.Write(" ");
        }
 
        for (j = 1; j <= i; j++)
        {
            Console.Write(prt);
        }
 
        for (k = 1; k <= (i - 1); k++)
        {
            Console.Write(prt);
        }
 
        space++;
        Console.WriteLine();
    }
 
    space = 3;
 
    for (i = 2; i <= 5; i++)
    {
        if ((i % 2) != 0)
        {
            for (sp = space; sp >= 1; sp--)
            {
                Console.Write(" ");
            }
 
            for (j = 1; j <= i; j++)
            {
                Console.Write(prt);
            }
        }
 
        if ((i % 2) != 0)
        {
            Console.WriteLine();
            space--;
        }
    }
}
}
 
// This code is contributed by Soumik

PHP

<?php
// PHP Program to print Kite Pattern
 
$space = 4;
$prt = '$';
 
for ($i = 1; $i <= 5; $i++)
{
 
    // For printing the space
    for ($sp = $space; $sp >= 1; $sp--)
    {
        echo (" ");
    }
 
    // For printing the $
    for ($j = 1; $j <= $i; $j++)
    {
        echo ( $prt);
    }
 
    for ($k = 1; $k <= ($i - 1); $k++)
    {
        if ($i == 1)
        {
            continue;
        }
 
        echo ( $prt);
    }
echo ("\n");
$space--;
}
 
$space = 1;
 
for ($i = 4; $i >= 1; $i--)
{
    for ($sp = $space; $sp >= 1; $sp--)
    {
        echo (" ");
    }
 
    for ($j = 1; $j <= $i; $j++)
    {
        echo ( $prt);
    }
 
    for ($k = 1; $k <= ($i - 1); $k++)
    {
        echo ( $prt);
    }
 
    $space++;
    echo ("\n");
}
 
$space = 3;
 
for ($i = 2; $i <= 5; $i++)
{
    if (($i % 2) != 0)
    {
        for ($sp = $space; $sp >= 1; $sp--)
        {
            echo (" ");
        }
 
        for ($j = 1; $j <= $i; $j++)
        {
            echo ( $prt);
        }
    }
 
    if (($i % 2) != 0)
    {
        echo ("\n");
        $space--;
    }
}
 
// This code is contributed
// by Sach_Code
?>

Javascript

<script>
 
      // JavaScript Program to print Kite Pattern
 
      var i,
        j,
        k,
        sp,
        space = 4;
      var prt = "$";
 
      for (i = 1; i <= 5; i++) {
        // For printing the space
        for (sp = space; sp >= 1; sp--) {
          document.write("  ");
        }
 
        // For printing the $
        for (j = 1; j <= i; j++) {
          document.write(prt);
        }
 
        for (k = 1; k <= i - 1; k++) {
          if (i == 1) {
            continue;
          }
 
          document.write(prt);
        }
        document.write("<br>");
        space--;
      }
 
      space = 1;
 
      for (i = 4; i >= 1; i--) {
        for (sp = space; sp >= 1; sp--) {
          document.write("  ");
        }
 
        for (j = 1; j <= i; j++) {
          document.write(prt);
        }
 
        for (k = 1; k <= i - 1; k++) {
          document.write(prt);
        }
 
        space++;
        document.write("<br>");
      }
 
      space = 3;
 
      for (i = 2; i <= 5; i++) {
        if (i % 2 != 0) {
          for (sp = space; sp >= 1; sp--) {
            document.write("  ");
          }
 
          for (j = 1; j <= i; j++) {
            document.write(prt);
          }
        }
 
        if (i % 2 != 0) {
          document.write("<br>");
          space--;
        }
      }
       
 </script>
Producción: 

    $
   $$$
  $$$$$
 $$$$$$$
$$$$$$$$$
 $$$$$$$
  $$$$$
   $$$
    $
   $$$
  $$$$$

 

Publicación traducida automáticamente

Artículo escrito por VipinKashyap 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 *