The slash wave pattern draws a row of mountain peaks with forward slashes and backslashes. It only needs two lines, because each slash already climbs or falls by itself.
Quick answer: Print " /\ " n times on the first line and "/ \" n times on the second. Each four-character block is one peak; side by side, the blocks join into a continuous wave. Four blocks give four peaks and a line sixteen characters long.
This program is part of the Wave Patterns collection.
Table of contents8 sections
Slash Wave Pattern output
Output (4 waves):
/\ /\ /\ /\ / \/ \/ \/ \

How the slash wave pattern works
Each peak is a tiny 4 × 2 drawing: the top line has the tip, /\, with a space either side, and the bottom line has the two feet, / and \, with two spaces between them. When the blocks are placed next to each other, the backslash of one peak meets the slash of the next, which makes the valleys. In code, a backslash has to be written as \\ inside a string.
- Print the block
" /\ "ntimes, then a new line. - Print the block
"/ \"ntimes, then a new line.
Key takeaways
- Each peak is a 4 × 2 block of characters.
- Neighbouring blocks share their valleys.
- A backslash is written
\\inside a string literal. - Java’s
repeatand Python’s*print a blockntimes without a loop.
Slash Wave Pattern in C
#include <stdio.h>
int main(void) {
int n = 4; /* number of waves */
for (int k = 0; k < n; k++)
printf(" /\\ ");
printf("\n");
for (int k = 0; k < n; k++)
printf("/ \\");
printf("\n");
return 0;
}Slash Wave Pattern in C++
#include <iostream>
using namespace std;
int main() {
int n = 4; // number of waves
for (int k = 0; k < n; k++)
cout << " /\\ ";
cout << endl;
for (int k = 0; k < n; k++)
cout << "/ \\";
cout << endl;
return 0;
}Slash Wave Pattern in Java
public class SlashWave {
public static void main(String[] args) {
int n = 4; // number of waves
System.out.println(" /\\ ".repeat(n));
System.out.println("/ \\".repeat(n));
}
}Slash Wave Pattern in Python
n = 4 # number of waves
print(" /\\ " * n)
print("/ \\" * n)Time and space complexity
The program prints two lines of 4n characters, so it runs in O(n) time with O(1) extra memory.
Frequently asked questions
How do I make taller peaks?
Use more lines per block. A peak of height 3 needs blocks like " /\ ", " / \ " and "/ \", which is the top half of the slash diamond.
Why does the code show four backslashes in some places?
Each pair stands for one backslash in the output. The C and C++ strings need \\ for every backslash you want to see.
Can I flip the waves upside down?
Yes. Print the feet line first with the slashes swapped, "\ /", and then " \/ ". The peaks then hang down like valleys.
How is it different from the mountain wave?
The mountain wave fills each peak with stars. The slash wave only draws the outline, so it looks lighter.






