Print the Mirror Image of Sine-Wave Pattern in C

In C programming, creating a mirror image of a sine-wave pattern involves printing a visual representation where waves appear to be reflected. This pattern uses the mathematical concept of symmetry to create wave-like shapes using characters.

Syntax

for(i = 1; i <= wave_height; i++) {
    for(j = 1; j <= wave_length; j++){
        for(k = 1; k <= wave_height; k++) {
            if(condition_for_wave_position) {
                printf("character");
            } else {
                printf("space");
            }
        }
    }
    printf("<br>");
}

Algorithm

  • Accept the wave height and wave length from user
  • Use nested loops to control row and column positions
  • Apply mathematical condition for mirror image positioning
  • Print wave character (^^) at calculated positions
  • Print spaces for other positions to maintain structure

Example

This program creates a sine wave mirror image pattern based on user-specified height and length −

#include <stdio.h>

int main() {
    int wave_height;
    int wave_length;
    int i, j, k;
    
    printf("Please enter the wave height of Sine Wave: ");
    scanf("%d", &wave_height);
    printf("Please enter the wave length of Sine Wave: ");
    scanf("%d", &wave_length);
    printf("<br>");
    
    for(i = 1; i <= wave_height; i++) {
        for(j = 1; j <= wave_length; j++){
            for(k = 1; k <= wave_height; k++) {
                if(i == k || i + k == wave_height + 1) {
                    printf("^^");
                } else {
                    printf("  ");
                }
            }
        }
        printf("<br>");
    }
    
    return 0;
}
Please enter the wave height of Sine Wave: 5
Please enter the wave length of Sine Wave: 3

^^        ^^^^        ^^        ^^^^        ^^
  ^^    ^^    ^^    ^^  ^^    ^^    ^^    ^^  
    ^^^^        ^^^^      ^^^^        ^^^^    
  ^^    ^^    ^^  ^^    ^^    ^^    ^^  ^^    
^^        ^^^^        ^^        ^^^^        ^^

How It Works

The pattern generation uses a mathematical condition i == k || i + k == wave_height + 1 where:

  • i == k creates the main diagonal of the wave
  • i + k == wave_height + 1 creates the mirror diagonal
  • The triple nested loop structure repeats the pattern horizontally
  • Each wave segment has height equal to wave_height

Key Points

  • The outer loop controls the number of rows (wave height)
  • The middle loop controls wave repetition (wave length)
  • The inner loop creates individual wave segments
  • Double characters ("^^") enhance visual appearance

Conclusion

This sine wave mirror pattern demonstrates nested loop control and mathematical conditions for creating symmetric visual patterns. The algorithm efficiently generates wave-like structures with customizable dimensions.

Updated on: 2026-03-15T12:35:38+05:30

463 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements