Programa para imprimir la imagen especular del patrón de onda sinusoidal

Dé la altura y el ancho de una onda para imprimir el patrón . Ejemplos:

Input : wave_height=5
        wave_length=10
Output :

>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>
  >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>  
    >>        >>        >>        >>        >>        >>        >>        >>        >>        >>    
  >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>  
>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>

Recomendado: pruebe su enfoque en {IDE} primero, antes de pasar a la solución.

Planteamiento: Primero, verifique la fila y la columna donde se necesitan imprimir los elementos. Luego, use bucles for anidados para imprimir los elementos en el orden correspondiente. Se mantienen bucles separados para realizar un seguimiento de wave_height y wave_length. 

C++

// C program to print Mirror Image of sign wave pattern.
#include <stdio.h>
 
// Function to print Mirror Image of sign wave pattern
void printWave(int wave_height, int wave_length)
{
    // for loop for height of wave
    for (int i = 1; i <= wave_height; i++) {
 
        // for loop for wave length
        for (int j = 1; j <= wave_length; j++)
        {
            // intermediate spaces
            for (int k = 1; k <= wave_height; k++) {
 
                if (i == k || i + k == wave_height + 1) {
                    // put any symbol
                    printf(">>");
                }
                else {
                    printf(" "" ");
                }
            }
        }
        printf("\n");
    }
}
 
// Driver code
int main()
{
    int wave_height = 5;
    int wave_length = 10;
    printWave(wave_height, wave_length);
    return 0;
}

Java

// Java program to print Mirror
// Image of sign wave pattern.
class GFG
{
// Function to print Mirror
// Image of sign wave pattern
static void printWave(int wave_height,
                      int wave_length)
{
    // for loop for height of wave
    for (int i = 1;
             i <= wave_height; i++)
    {
        // for loop for wave length
        for (int j = 1;
                 j <= wave_length; j++)
        {
            // intermediate spaces
            for (int k = 1;
                     k <= wave_height; k++)
            {
 
                if (i == k || i + k == wave_height + 1)
                {
                    // put any symbol
                    System.out.printf(">>");
                }
                else {
                    System.out.printf(" " + " ");
                }
            }
        }
        System.out.printf("\n");
    }
}
 
// Driver code
public static void main(String[] args)
{
    int wave_height = 5;
    int wave_length = 10;
    printWave(wave_height, wave_length);
}
}
 
// This code is contributed
// by Smitha

Python3

# Python3 program to prMirror
# Image of sign wave pattern.
 
# Function to prMirror Image
# of sign wave pattern
def printWave(wave_height, wave_length):
 
    # for loop for height of wave
    for i in range(1, wave_height + 1, 1):
 
        # for loop for wave length
        for j in range(1, wave_length + 1, 1):
 
            # intermediate spaces
            for k in range(1, wave_height + 1, 1):
 
                if (i == k or
                    i + k == wave_height + 1):
         
                    # put any symbol
                    print(">>", end = "");
 
                else:
                    print(" ", end = " ");
 
        print();
 
# Driver code
if __name__ == '__main__':
    wave_height = 5;
    wave_length = 10;
    printWave(wave_height, wave_length);
 
# This code is contributed by PrinciRaj1992

C#

// C# program to print Mirror
// Image of sign wave pattern.
using System;
class GFG
{
// Function to print Mirror
// Image of sign wave pattern
static void printWave(int wave_height,
                    int wave_length)
{
    // for loop for height of wave
    for (int i = 1;
            i <= wave_height; i++)
    {
        // for loop for wave length
        for (int j = 1;
                j <= wave_length; j++)
        {
            // intermediate spaces
            for (int k = 1;
                    k <= wave_height; k++)
            {
 
                if (i == k || i + k == wave_height + 1)
                {
                    // put any symbol
                    Console.Write(">>");
                }
                else {
                    Console.Write(" " + " ");
                }
            }
        }
    Console.Write("\n");
    }
}
 
// Driver code
public static void Main()
{
    int wave_height = 5;
    int wave_length = 10;
    printWave(wave_height, wave_length);
}
}
 
// This code is contributed
// by Smitha

Javascript

<script>
 
// JavaScript program to print Mirror Image of sign wave pattern.
 
// Function to print Mirror Image of sign wave pattern
function printWave(wave_height, wave_length)
{
 
    // for loop for height of wave
    for (let i = 1; i <= wave_height; i++) {
 
        // for loop for wave length
        for (let j = 1; j <= wave_length; j++)
        {
            // intermediate spaces
            for (let k = 1; k <= wave_height; k++) {
 
                if (i == k || i + k == wave_height + 1) {
                    // put any symbol
                    document.write(">>");
                }
                else {
                    document.write(" ",' ');
                }
            }
        }
        document.write("</br>");
    }
}
 
// Driver code
let wave_height = 5;
let wave_length = 10;
printWave(wave_height, wave_length);
 
// This code is contributed by shinjanpatra
 
</script>

Producción

>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>
  >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>  
    >>        >>        >>        >>        >>        >>        >>        >>        >>        >>    
  >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>    >>  >>  
>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>>>      >>

Publicación traducida automáticamente

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