Program to Print Mirror Image of Sine-Wave Pattern

A sine wave is a mathematical curve that oscillates between a maximum and minimum value, smoothly transitioning between positive and negative values. It is commonly used to represent periodic phenomena such as sound, light, and electrical signals.
Examples: Give the Height and Width of a Wave to print the pattern.
Input : wave_height=5
wave_length=10
Output :
>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>
>> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
>> >> >> >> >> >> >> >> >> >>
>> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>
Recommended: Please try your approach on {IDE} first, before moving on to the solution.
Approach
First, check the row and column where the elements are needed to be printed. Then, use nested for loops to print the elements in the corresponding order. Separate loops are kept to keep track of the wave_height and wave_length.Â
Java
// Java program to print Mirror// Image of sign wave pattern.class GFG{// Function to print Mirror// Image of sign wave patternstatic 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 codepublic 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 patterndef 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 codeif __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 patternfunction 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 codelet wave_height = 5;let wave_length = 10;printWave(wave_height, wave_length);Â
// This code is contributed by shinjanpatraÂ
</script> |
C++
// C program to print Mirror Image of sign wave pattern.#include <stdio.h>Â
// Function to print Mirror Image of sign wave patternvoid 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 codeint main(){Â Â Â Â int wave_height = 5;Â Â Â Â int wave_length = 10;Â Â Â Â printWave(wave_height, wave_length);Â Â Â Â return 0;} |
Output:
>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>
>> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
>> >> >> >> >> >> >> >> >> >>
>> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >>
>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>
Time complexity: O((wave_height2)*wave_length)
Auxiliary space: O(1)
Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 zambiatek!
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 zambiatek!



