Posted on by Kalkicode
Code Pattern

Program For Sine-Wave Pattern

Given a size which is indicate the height of wave. And N is indicate number of sequence of wave. Our goal is to print simple sine wave using of this parameter. Let's first view few examples of this problem.

In above example width of sine wave are constant. Only modified that occurring sequence and height. Here given code implementation process.

``````//C Program
//Program For Sine-Wave Pattern
#include <stdio.h>

void space(int size)
{
for (int i = 0; i < size; ++i)
{
printf(" ");
}
}
void show_pattern(int size, int n)
{
if (size <= 2)
{
return;
}
printf("Size : %d  N : %d\n\n", size, n);
//First layer of sine wave
for (int j = 0; j < n; ++j)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
printf("✰ ✰");
}
printf("\n");
// Intermediate layer of sine wave
for (int i = 0; i < size - 2; ++i)
{
for (int j = 0; j < n; ++j)
{
space(5);
printf("✰");
space(5);
printf("✰");
}
printf("\n");
}
//Last layer of sine wave
for (int j = 0; j <= n; ++j)
{
if (j == 0)
{
printf(" ✰ ✰");
}
else
{
space(9);
printf("✰ ✰");
}
}
printf("\n\n");
}
int main()
{
//Test Case
show_pattern(6, 1);
show_pattern(7, 3);
show_pattern(3, 4);
return 0;
}``````

Output

``````Size : 6  N : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Size : 7  N : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Size : 3  N : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````/*
Java Program
Program For Sine-Wave Pattern
*/
public class MyPattern
{
// Include space of given size
public void space(int size)
{
for (int i = 0; i < size; ++i)
{
System.out.print(" ");
}
}
public void showPattern(int height, int width)
{
if (height <= 2)
{
return;
}
// Display given size
System.out.print("Height : " + height +
" Width : " + width + "\n\n");
// First layer of sine wave
for (int j = 0; j < width; ++j)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
System.out.print("✰ ✰");
}
System.out.print("\n");
// Intermediate layer of sine wave
for (int i = 0; i < height - 2; ++i)
{
for (int j = 0; j < width; ++j)
{
space(5);
System.out.print("✰");
space(5);
System.out.print("✰");
}
System.out.print("\n");
}
// Last layer of sine wave
for (int j = 0; j <= width; ++j)
{
if (j == 0)
{
System.out.print(" ✰ ✰");
}
else
{
space(9);
System.out.print("✰ ✰");
}
}
System.out.print("\n\n");
}
public static void main(String[] args)
{
MyPattern obj = new MyPattern();
// Test A
// height : 6
// width  : 1
obj.showPattern(6, 1);
// Test B
// height : 7
// width  : 3
obj.showPattern(7, 3);
// Test C
// height : 3
// width  : 4
obj.showPattern(3, 4);
}
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````// Include header file
#include <iostream>
using namespace std;
/*
C++ Program
Program For Sine-Wave Pattern
*/
class MyPattern
{
public:
// Include space of given size
void space(int size)
{
for (int i = 0; i < size; ++i)
{
cout << " ";
}
}
void showPattern(int height, int width)
{
if (height <= 2)
{
return;
}
// Display given size
cout << "Height : " << height
<< " Width : " << width << "\n\n";
// First layer of sine wave
for (int j = 0; j < width; ++j)
{
if (j == 0)
{
this->space(7);
}
else
{
this->space(9);
}
cout << "✰ ✰";
}
cout << "\n";
// Intermediate layer of sine wave
for (int i = 0; i < height - 2; ++i)
{
for (int j = 0; j < width; ++j)
{
this->space(5);
cout << "✰";
this->space(5);
cout << "✰";
}
cout << "\n";
}
// Last layer of sine wave
for (int j = 0; j <= width; ++j)
{
if (j == 0)
{
cout << " ✰ ✰";
}
else
{
this->space(9);
cout << "✰ ✰";
}
}
cout << "\n\n";
}
};
int main()
{
MyPattern *obj = new MyPattern();
// Test A
// height : 6
// width  : 1
obj->showPattern(6, 1);
// Test B
// height : 7
// width  : 3
obj->showPattern(7, 3);
// Test C
// height : 3
// width  : 4
obj->showPattern(3, 4);
return 0;
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````// Include namespace system
using System;
/*
Csharp Program
Program For Sine-Wave Pattern
*/
public class MyPattern
{
// Include space of given size
public void space(int size)
{
for (int i = 0; i < size; ++i)
{
Console.Write(" ");
}
}
public void showPattern(int height, int width)
{
if (height <= 2)
{
return;
}
// Display given size
Console.Write("Height : " + height +
" Width : " + width + "\n\n");
// First layer of sine wave
for (int j = 0; j < width; ++j)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
Console.Write("✰ ✰");
}
Console.Write("\n");
// Intermediate layer of sine wave
for (int i = 0; i < height - 2; ++i)
{
for (int j = 0; j < width; ++j)
{
this.space(5);
Console.Write("✰");
this.space(5);
Console.Write("✰");
}
Console.Write("\n");
}
// Last layer of sine wave
for (int j = 0; j <= width; ++j)
{
if (j == 0)
{
Console.Write(" ✰ ✰");
}
else
{
this.space(9);
Console.Write("✰ ✰");
}
}
Console.Write("\n\n");
}
public static void Main(String[] args)
{
MyPattern obj = new MyPattern();
// Test A
// height : 6
// width  : 1
obj.showPattern(6, 1);
// Test B
// height : 7
// width  : 3
obj.showPattern(7, 3);
// Test C
// height : 3
// width  : 4
obj.showPattern(3, 4);
}
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````<?php
/*
Php Program
Program For Sine-Wave Pattern
*/
class MyPattern
{
// Include space of given size
public  function space(\$size)
{
for (\$i = 0; \$i < \$size; ++\$i)
{
echo(" ");
}
}
public  function showPattern(\$height, \$width)
{
if (\$height <= 2)
{
return;
}
// Display given size
echo("Height : ".\$height.
" Width : ".\$width.
"\n\n");
// First layer of sine wave
for (\$j = 0; \$j < \$width; ++\$j)
{
if (\$j == 0)
{
\$this->space(7);
}
else
{
\$this->space(9);
}
echo("✰ ✰");
}
echo("\n");
// Intermediate layer of sine wave
for (\$i = 0; \$i < \$height - 2; ++\$i)
{
for (\$j = 0; \$j < \$width; ++\$j)
{
\$this->space(5);
echo("✰");
\$this->space(5);
echo("✰");
}
echo("\n");
}
// Last layer of sine wave
for (\$j = 0; \$j <= \$width; ++\$j)
{
if (\$j == 0)
{
echo(" ✰ ✰");
}
else
{
\$this->space(9);
echo("✰ ✰");
}
}
echo("\n\n");
}
}

function main()
{
\$obj = new MyPattern();
// Test A
// height : 6
// width  : 1
\$obj->showPattern(6, 1);
// Test B
// height : 7
// width  : 3
\$obj->showPattern(7, 3);
// Test C
// height : 3
// width  : 4
\$obj->showPattern(3, 4);
}
main();``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````/*
Node JS Program
Program For Sine-Wave Pattern
*/
class MyPattern
{
// Include space of given size
space(size)
{
for (var i = 0; i < size; ++i)
{
process.stdout.write(" ");
}
}
showPattern(height, width)
{
if (height <= 2)
{
return;
}
// Display given size
process.stdout.write("Height : " + height +
" Width : " + width + "\n\n");
// First layer of sine wave
for (var j = 0; j < width; ++j)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
process.stdout.write("✰ ✰");
}
process.stdout.write("\n");
// Intermediate layer of sine wave
for (var i = 0; i < height - 2; ++i)
{
for (var j = 0; j < width; ++j)
{
this.space(5);
process.stdout.write("✰");
this.space(5);
process.stdout.write("✰");
}
process.stdout.write("\n");
}
// Last layer of sine wave
for (var j = 0; j <= width; ++j)
{
if (j == 0)
{
process.stdout.write(" ✰ ✰");
}
else
{
this.space(9);
process.stdout.write("✰ ✰");
}
}
process.stdout.write("\n\n");
}
}

function main()
{
var obj = new MyPattern();
// Test A
// height : 6
// width  : 1
obj.showPattern(6, 1);
// Test B
// height : 7
// width  : 3
obj.showPattern(7, 3);
// Test C
// height : 3
// width  : 4
obj.showPattern(3, 4);
}
main();``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````#  Python 3 Program
#  Program For Sine-Wave Pattern
class MyPattern :
#  Include space of given size
def space(self, size) :
i = 0
while (i < size) :
print(" ", end = "")
i += 1

def showPattern(self, height, width) :
if (height <= 2) :
return

#  Display given size
print("Height : ", height ,
" Width : ", width ,"\n")
j = 0
#  First layer of sine wave
while (j < width) :
if (j == 0) :
self.space(7)
else :
self.space(9)

print("✰ ✰", end = "")
j += 1

print(end = "\n")
i = 0
#  Intermediate layer of sine wave
while (i < height - 2) :
j = 0
while (j < width) :
self.space(5)
print("✰", end = "")
self.space(5)
print("✰", end = "")
j += 1

print(end = "\n")
i += 1

j = 0
#  Last layer of sine wave
while (j <= width) :
if (j == 0) :
print(" ✰ ✰", end = "")
else :
self.space(9)
print("✰ ✰", end = "")

j += 1

print("\n")

def main() :
obj = MyPattern()
#  Test A
#  height : 6
#  width  : 1
obj.showPattern(6, 1)
#  Test B
#  height : 7
#  width  : 3
obj.showPattern(7, 3)
#  Test C
#  height : 3
#  width  : 4
obj.showPattern(3, 4)

if __name__ == "__main__": main()``````

Output

``````Height :  6  Width :  1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Height :  7  Width :  3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Height :  3  Width :  4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````#  Ruby Program
#  Program For Sine-Wave Pattern
class MyPattern
#  Include space of given size
def space(size)
i = 0
while (i < size)
print(" ")
i += 1
end

end

def showPattern(height, width)
if (height <= 2)
return
end

#  Display given size
print("Height : ", height ,
" Width : ", width ,"\n\n")
j = 0
#  First layer of sine wave
while (j < width)
if (j == 0)
self.space(7)
else

self.space(9)
end

print("✰ ✰")
j += 1
end

print("\n")
i = 0
#  Intermediate layer of sine wave
while (i < height - 2)
j = 0
while (j < width)
self.space(5)
print("✰")
self.space(5)
print("✰")
j += 1
end

print("\n")
i += 1
end

j = 0
#  Last layer of sine wave
while (j <= width)
if (j == 0)
print(" ✰ ✰")
else

self.space(9)
print("✰ ✰")
end

j += 1
end

print("\n\n")
end

end

def main()
obj = MyPattern.new()
#  Test A
#  height : 6
#  width  : 1
obj.showPattern(6, 1)
#  Test B
#  height : 7
#  width  : 3
obj.showPattern(7, 3)
#  Test C
#  height : 3
#  width  : 4
obj.showPattern(3, 4)
end

main()``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

``````
``````/*
Scala Program
Program For Sine-Wave Pattern
*/
class MyPattern()
{
// Include space of given size
def space(size: Int): Unit = {
var i: Int = 0;
while (i < size)
{
print(" ");
i += 1;
}
}
def showPattern(height: Int, width: Int): Unit = {
if (height <= 2)
{
return;
}
// Display given size
print("Height : " + height +
" Width : " + width + "\n\n");
var j: Int = 0;
// First layer of sine wave
while (j < width)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
print("✰ ✰");
j += 1;
}
print("\n");
var i: Int = 0;
// Intermediate layer of sine wave
while (i < height - 2)
{
j = 0;
while (j < width)
{
space(5);
print("✰");
space(5);
print("✰");
j += 1;
}
print("\n");
i += 1;
}
j = 0;
// Last layer of sine wave
while (j <= width)
{
if (j == 0)
{
print(" ✰ ✰");
}
else
{
space(9);
print("✰ ✰");
}
j += 1;
}
print("\n\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: MyPattern = new MyPattern();
// Test A
// height : 6
// width  : 1
obj.showPattern(6, 1);
// Test B
// height : 7
// width  : 3
obj.showPattern(7, 3);
// Test C
// height : 3
// width  : 4
obj.showPattern(3, 4);
}
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````/*
Swift 4 Program
Program For Sine-Wave Pattern
*/
class MyPattern
{
// Include space of given size
func space(_ size: Int)
{
var i: Int = 0;
while (i < size)
{
print(" ", terminator: "");
i += 1;
}
}
func showPattern(_ height: Int, _ width: Int)
{
if (height <= 2)
{
return;
}
// Display given size
print("Height : ", height ,
" Width : ", width ,"\n");
var j: Int = 0;
// First layer of sine wave
while (j < width)
{
if (j == 0)
{
self.space(7);
}
else
{
self.space(9);
}
print("✰ ✰", terminator: "");
j += 1;
}
print(terminator: "\n");
var i: Int = 0;
// Intermediate layer of sine wave
while (i < height - 2)
{
j = 0;
while (j < width)
{
self.space(5);
print("✰", terminator: "");
self.space(5);
print("✰", terminator: "");
j += 1;
}
print(terminator: "\n");
i += 1;
}
j = 0;
// Last layer of sine wave
while (j <= width)
{
if (j == 0)
{
print(" ✰ ✰", terminator: "");
}
else
{
self.space(9);
print("✰ ✰", terminator: "");
}
j += 1;
}
print("\n");
}
}
func main()
{
let obj: MyPattern = MyPattern();
// Test A
// height : 6
// width  : 1
obj.showPattern(6, 1);
// Test B
// height : 7
// width  : 3
obj.showPattern(7, 3);
// Test C
// height : 3
// width  : 4
obj.showPattern(3, 4);
}
main();``````

Output

``````Height :  6  Width :  1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Height :  7  Width :  3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Height :  3  Width :  4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````/*
Kotlin Program
Program For Sine-Wave Pattern
*/
class MyPattern
{
// Include space of given size
fun space(size: Int): Unit
{
var i: Int = 0;
while (i < size)
{
print(" ");
i += 1;
}
}
fun showPattern(height: Int, width: Int): Unit
{
if (height <= 2)
{
return;
}
// Display given size
print("Height : " + height + " Width : " + width + "\n\n");
var j: Int = 0;
// First layer of sine wave
while (j < width)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
print("✰ ✰");
j += 1;
}
print("\n");
var i: Int = 0;
// Intermediate layer of sine wave
while (i < height - 2)
{
j = 0;
while (j < width)
{
this.space(5);
print("✰");
this.space(5);
print("✰");
j += 1;
}
print("\n");
i += 1;
}
j = 0;
// Last layer of sine wave
while (j <= width)
{
if (j == 0)
{
print(" ✰ ✰");
}
else
{
this.space(9);
print("✰ ✰");
}
j += 1;
}
print("\n\n");
}
}
fun main(args: Array < String > ): Unit
{
val obj: MyPattern = MyPattern();
// Test A
// height : 6
// width  : 1
obj.showPattern(6, 1);
// Test B
// height : 7
// width  : 3
obj.showPattern(7, 3);
// Test C
// height : 3
// width  : 4
obj.showPattern(3, 4);
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````package main
import "fmt"
/*
Go Program
Program For Sine-Wave Pattern
*/
type MyPattern struct {}
func getMyPattern() * MyPattern {
var me *MyPattern = &MyPattern {}
return me
}
// Include space of given size
func(this MyPattern) space(size int) {
for i := 0 ; i < size ; i++ {
fmt.Print(" ")
}
}
func(this MyPattern) showPattern(height, width int) {
if height <= 2 {
return
}
// Display given size
fmt.Print("Height : ", height,
" Width : ", width, "\n\n")
// First layer of sine wave
for j := 0 ; j < width ; j++ {
if j == 0 {
this.space(7)
} else {
this.space(9)
}
fmt.Print("✰ ✰")
}
fmt.Print("\n")
// Intermediate layer of sine wave
for i := 0 ; i < height - 2 ; i++ {
for j := 0 ; j < width ; j++ {
this.space(5)
fmt.Print("✰")
this.space(5)
fmt.Print("✰")
}
fmt.Print("\n")
}
// Last layer of sine wave
for j := 0 ; j <= width ; j++ {
if j == 0 {
fmt.Print(" ✰ ✰")
} else {
this.space(9)
fmt.Print("✰ ✰")
}
}
fmt.Print("\n\n")
}
func main() {
var obj * MyPattern = getMyPattern()
// Test A
// height : 6
// width  : 1
obj.showPattern(6, 1)
// Test B
// height : 7
// width  : 3
obj.showPattern(7, 3)
// Test C
// height : 3
// width  : 4
obj.showPattern(3, 4)
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````// Rust Language
// Program For Sine-Wave Pattern
fn main()
{
//Test Case
show_pattern(6, 1);
show_pattern(7, 3);
show_pattern(3, 4);
}
fn show_pattern(size: i32, n: i32)
{
if size <= 2
{
return;
}
print!("Size : {} N : {}\n\n", size, n);
let mut j: i32 = 0;
//First layer of sine wave
while j < n
{
if j == 0
{
space(7);
}
else
{
space(9);
}
print!("✰ ✰");
j += 1;
}
print!("\n");
let mut i: i32 = 0;
let mut j: i32;
// Intermediate layer of sine wave
while i < size - 2
{
j = 0;
while j < n
{
space(5);
print!("✰");
space(5);
print!("✰");
j += 1;
}
print!("\n");
i += 1;
}
j = 0;
//Last layer of sine wave
while j <= n
{
if j == 0
{
print!(" ✰ ✰");
}
else
{
space(9);
print!("✰ ✰");
}
j += 1;
}
print!("\n\n");
}
fn space(size: i32)
{
let mut i: i32 = 0;
while i < size
{
print!(" ");
i += 1;
}
}``````

Output

``````Size : 6 N : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰

Size : 7 N : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

Size : 3 N : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````// Java Program
// Program For Sine-Wave Pattern Set-B
class MyPattern
{
// include space
public void space(int size)
{
for (int i = 0; i < size; ++i)
{
System.out.print(" ");
}
}
public void showPattern(int hight, int width)
{
if (hight <= 2)
{
return;
}
// Display given Height Width
System.out.print("Height : " + hight +
" Width : " + width + "\n\n");
//First layer of sine wave
for (int j = 0; j <= width; ++j)
{
if (j == 0)
{
System.out.print(" * *");
}
else
{
space(9);
System.out.print("* *");
}
}
System.out.print("\n");
// Intermediate layer of sine wave
for (int i = 0; i < hight - 2; ++i)
{
for (int j = 0; j < width; ++j)
{
space(5);
System.out.print("*");
space(5);
System.out.print("*");
}
System.out.print("\n");
}
//Last layer of sine wave
for (int j = 0; j < width; ++j)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
System.out.print("* *");
}
System.out.print("\n\n");
}
public static void main(String[] args)
{
MyPattern obj = new MyPattern();
//Test Case
obj.showPattern(6, 1);
obj.showPattern(7, 3);
obj.showPattern(3, 4);
}
}``````

Output

``````Height : 6 Width : 1

* *         * *
*     *
*     *
*     *
*     *
* *

Height : 7 Width : 3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Height : 3 Width : 4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````// Include header file
#include <iostream>
using namespace std;
// C++ Program
// Program For Sine-Wave Pattern Set-B
class MyPattern
{
public:
// include space
void space(int size)
{
for (int i = 0; i < size; ++i)
{
cout << " ";
}
}
void showPattern(int hight, int width)
{
if (hight <= 2)
{
return;
}
// Display given Height Width
cout << "Height : " << hight
<< " Width : " << width << "\n\n";
//First layer of sine wave
for (int j = 0; j <= width; ++j)
{
if (j == 0)
{
cout << " * *";
}
else
{
this->space(9);
cout << "* *";
}
}
cout << "\n";
// Intermediate layer of sine wave
for (int i = 0; i < hight - 2; ++i)
{
for (int j = 0; j < width; ++j)
{
this->space(5);
cout << "*";
this->space(5);
cout << "*";
}
cout << "\n";
}
// Last layer of sine wave
for (int j = 0; j < width; ++j)
{
if (j == 0)
{
this->space(7);
}
else
{
this->space(9);
}
cout << "* *";
}
cout << "\n\n";
}
};
int main()
{
MyPattern *obj = new MyPattern();
//Test Case
obj->showPattern(6, 1);
obj->showPattern(7, 3);
obj->showPattern(3, 4);
return 0;
}``````

Output

``````Height : 6 Width : 1

* *         * *
*     *
*     *
*     *
*     *
* *

Height : 7 Width : 3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Height : 3 Width : 4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````// Include namespace system
using System;
// Csharp Program
// Program For Sine-Wave Pattern Set-B
public class MyPattern
{
// include space
public void space(int size)
{
for (int i = 0; i < size; ++i)
{
Console.Write(" ");
}
}
public void showPattern(int hight, int width)
{
if (hight <= 2)
{
return;
}
// Display given Height Width
Console.Write("Height : " + hight + " Width : " + width + "\n\n");
//First layer of sine wave
for (int j = 0; j <= width; ++j)
{
if (j == 0)
{
Console.Write(" * *");
}
else
{
this.space(9);
Console.Write("* *");
}
}
Console.Write("\n");
// Intermediate layer of sine wave
for (int i = 0; i < hight - 2; ++i)
{
for (int j = 0; j < width; ++j)
{
this.space(5);
Console.Write("*");
this.space(5);
Console.Write("*");
}
Console.Write("\n");
}
//Last layer of sine wave
for (int j = 0; j < width; ++j)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
Console.Write("* *");
}
Console.Write("\n\n");
}
public static void Main(String[] args)
{
MyPattern obj = new MyPattern();
//Test Case
obj.showPattern(6, 1);
obj.showPattern(7, 3);
obj.showPattern(3, 4);
}
}``````

Output

``````Height : 6 Width : 1

* *         * *
*     *
*     *
*     *
*     *
* *

Height : 7 Width : 3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Height : 3 Width : 4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````<?php
// Php Program
// Program For Sine-Wave Pattern Set-B
class MyPattern
{
// include space
public  function space(\$size)
{
for (\$i = 0; \$i < \$size; ++\$i)
{
echo(" ");
}
}
public  function showPattern(\$hight, \$width)
{
if (\$hight <= 2)
{
return;
}
// Display given Height Width
echo("Height : ".\$hight.
" Width : ".\$width.
"\n\n");
//First layer of sine wave
for (\$j = 0; \$j <= \$width; ++\$j)
{
if (\$j == 0)
{
echo(" * *");
}
else
{
\$this->space(9);
echo("* *");
}
}
echo("\n");
// Intermediate layer of sine wave
for (\$i = 0; \$i < \$hight - 2; ++\$i)
{
for (\$j = 0; \$j < \$width; ++\$j)
{
\$this->space(5);
echo("*");
\$this->space(5);
echo("*");
}
echo("\n");
}
//Last layer of sine wave
for (\$j = 0; \$j < \$width; ++\$j)
{
if (\$j == 0)
{
\$this->space(7);
}
else
{
\$this->space(9);
}
echo("* *");
}
echo("\n\n");
}
}

function main()
{
\$obj = new MyPattern();
//Test Case
\$obj->showPattern(6, 1);
\$obj->showPattern(7, 3);
\$obj->showPattern(3, 4);
}
main();``````

Output

``````Height : 6 Width : 1

* *         * *
*     *
*     *
*     *
*     *
* *

Height : 7 Width : 3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Height : 3 Width : 4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````// Node JS Program
// Program For Sine-Wave Pattern Set-B
class MyPattern
{
// include space
space(size)
{
for (var i = 0; i < size; ++i)
{
process.stdout.write(" ");
}
}
showPattern(hight, width)
{
if (hight <= 2)
{
return;
}
// Display given Height Width
process.stdout.write("Height : " + hight +
" Width : " + width + "\n\n");
//First layer of sine wave
for (var j = 0; j <= width; ++j)
{
if (j == 0)
{
process.stdout.write(" * *");
}
else
{
this.space(9);
process.stdout.write("* *");
}
}
process.stdout.write("\n");
// Intermediate layer of sine wave
for (var i = 0; i < hight - 2; ++i)
{
for (var j = 0; j < width; ++j)
{
this.space(5);
process.stdout.write("*");
this.space(5);
process.stdout.write("*");
}
process.stdout.write("\n");
}
//Last layer of sine wave
for (var j = 0; j < width; ++j)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
process.stdout.write("* *");
}
process.stdout.write("\n\n");
}
}

function main()
{
var obj = new MyPattern();
//Test Case
obj.showPattern(6, 1);
obj.showPattern(7, 3);
obj.showPattern(3, 4);
}
main();``````

Output

``````Height : 6 Width : 1

* *         * *
*     *
*     *
*     *
*     *
* *

Height : 7 Width : 3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Height : 3 Width : 4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````#  Python 3 Program
#  Program For Sine-Wave Pattern Set-B
class MyPattern :
#  include space
def space(self, size) :
i = 0
while (i < size) :
print(" ", end = "")
i += 1

def showPattern(self, hight, width) :
if (hight <= 2) :
return

#  Display given Height Width
print("Height : ", hight ,
" Width : ", width ,"\n")
j = 0
# First layer of sine wave
while (j <= width) :
if (j == 0) :
print(" * *", end = "")
else :
self.space(9)
print("* *", end = "")

j += 1

print(end = "\n")
i = 0
#  Intermediate layer of sine wave
while (i < hight - 2) :
j = 0
while (j < width) :
self.space(5)
print("*", end = "")
self.space(5)
print("*", end = "")
j += 1

print(end = "\n")
i += 1

j = 0
# Last layer of sine wave
while (j < width) :
if (j == 0) :
self.space(7)
else :
self.space(9)

print("* *", end = "")
j += 1

print("\n")

def main() :
obj = MyPattern()
# Test Case
obj.showPattern(6, 1)
obj.showPattern(7, 3)
obj.showPattern(3, 4)

if __name__ == "__main__": main()``````

Output

``````Height :  6  Width :  1

* *         * *
*     *
*     *
*     *
*     *
* *

Height :  7  Width :  3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Height :  3  Width :  4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````#  Ruby Program
#  Program For Sine-Wave Pattern Set-B
class MyPattern
#  include space
def space(size)
i = 0
while (i < size)
print(" ")
i += 1
end

end

def showPattern(hight, width)
if (hight <= 2)
return
end

#  Display given Height Width
print("Height : ", hight ,
" Width : ", width ,"\n\n")
j = 0
# First layer of sine wave
while (j <= width)
if (j == 0)
print(" * *")
else

self.space(9)
print("* *")
end

j += 1
end

print("\n")
i = 0
#  Intermediate layer of sine wave
while (i < hight - 2)
j = 0
while (j < width)
self.space(5)
print("*")
self.space(5)
print("*")
j += 1
end

print("\n")
i += 1
end

j = 0
# Last layer of sine wave
while (j < width)
if (j == 0)
self.space(7)
else

self.space(9)
end

print("* *")
j += 1
end

print("\n\n")
end

end

def main()
obj = MyPattern.new()
# Test Case
obj.showPattern(6, 1)
obj.showPattern(7, 3)
obj.showPattern(3, 4)
end

main()``````

Output

``````Height : 6 Width : 1

* *         * *
*     *
*     *
*     *
*     *
* *

Height : 7 Width : 3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Height : 3 Width : 4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *

``````
``````// Scala Program
// Program For Sine-Wave Pattern Set-B
class MyPattern()
{
// include space
def space(size: Int): Unit = {
var i: Int = 0;
while (i < size)
{
print(" ");
i += 1;
}
}
def showPattern(hight: Int, width: Int): Unit = {
if (hight <= 2)
{
return;
}
// Display given Height Width
print("Height : " + hight + " Width : " + width + "\n\n");
var j: Int = 0;
//First layer of sine wave
while (j <= width)
{
if (j == 0)
{
print(" * *");
}
else
{
space(9);
print("* *");
}
j += 1;
}
print("\n");
var i: Int = 0;
// Intermediate layer of sine wave
while (i < hight - 2)
{
j = 0;
while (j < width)
{
space(5);
print("*");
space(5);
print("*");
j += 1;
}
print("\n");
i += 1;
}
j = 0;
// Last layer of sine wave
while (j < width)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
print("* *");
j += 1;
}
print("\n\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: MyPattern = new MyPattern();
//Test Case
obj.showPattern(6, 1);
obj.showPattern(7, 3);
obj.showPattern(3, 4);
}
}``````

Output

``````Height : 6 Width : 1

* *         * *
*     *
*     *
*     *
*     *
* *

Height : 7 Width : 3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Height : 3 Width : 4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````// Swift 4 Program
// Program For Sine-Wave Pattern Set-B
class MyPattern
{
// include space
func space(_ size: Int)
{
var i: Int = 0;
while (i < size)
{
print(" ", terminator: "");
i += 1;
}
}
func showPattern(_ hight: Int, _ width: Int)
{
if (hight <= 2)
{
return;
}
// Display given Height Width
print("Height : ", hight ,
" Width : ", width ,"\n");
var j: Int = 0;
//First layer of sine wave
while (j <= width)
{
if (j == 0)
{
print(" * *", terminator: "");
}
else
{
self.space(9);
print("* *", terminator: "");
}
j += 1;
}
print(terminator: "\n");
var i: Int = 0;
// Intermediate layer of sine wave
while (i < hight - 2)
{
j = 0;
while (j < width)
{
self.space(5);
print("*", terminator: "");
self.space(5);
print("*", terminator: "");
j += 1;
}
print(terminator: "\n");
i += 1;
}
j = 0;
// Last layer of sine wave
while (j < width)
{
if (j == 0)
{
self.space(7);
}
else
{
self.space(9);
}
print("* *", terminator: "");
j += 1;
}
print("\n");
}
}
func main()
{
let obj: MyPattern = MyPattern();
//Test Case
obj.showPattern(6, 1);
obj.showPattern(7, 3);
obj.showPattern(3, 4);
}
main();``````

Output

``````Height :  6  Width :  1

* *         * *
*     *
*     *
*     *
*     *
* *

Height :  7  Width :  3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Height :  3  Width :  4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````// Kotlin Program
// Program For Sine-Wave Pattern Set-B
class MyPattern
{
// include space
fun space(size: Int): Unit
{
var i: Int = 0;
while (i < size)
{
print(" ");
i += 1;
}
}
fun showPattern(hight: Int, width: Int): Unit
{
if (hight <= 2)
{
return;
}
// Display given Height Width
print("Height : " + hight + " Width : " + width + "\n\n");
var j: Int = 0;
//First layer of sine wave
while (j <= width)
{
if (j == 0)
{
print(" * *");
}
else
{
this.space(9);
print("* *");
}
j += 1;
}
print("\n");
var i: Int = 0;
// Intermediate layer of sine wave
while (i < hight - 2)
{
j = 0;
while (j < width)
{
this.space(5);
print("*");
this.space(5);
print("*");
j += 1;
}
print("\n");
i += 1;
}
j = 0;
//Last layer of sine wave
while (j < width)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
print("* *");
j += 1;
}
print("\n\n");
}
}
fun main(args: Array < String > ): Unit
{
val obj: MyPattern = MyPattern();
//Test Case
obj.showPattern(6, 1);
obj.showPattern(7, 3);
obj.showPattern(3, 4);
}``````

Output

``````Height : 6 Width : 1

* *         * *
*     *
*     *
*     *
*     *
* *

Height : 7 Width : 3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Height : 3 Width : 4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````fn main()
{
//Test Case
show_pattern(6, 1);
show_pattern(7, 3);
show_pattern(3, 4);
}
fn show_pattern(size: i32, n: i32)
{
if size <= 2
{
return;
}
print!("Size : {} N : {}\n\n", size, n);
let mut j: i32 = 0;
let mut i: i32 = 0;
//First layer of sine wave
while j <= n
{
if j == 0
{
print!(" * *");
}
else
{
space(9);
print!("* *");
}
j += 1;
}
print!("\n");
// Intermediate layer of sine wave
while i < size - 2
{
j = 0;
while j < n
{
space(5);
print!("*");
space(5);
print!("*");
j += 1;
}
print!("\n");
i += 1;
}
j = 0;
//Last layer of sine wave
while j < n
{
if j == 0
{
space(7);
}
else
{
space(9);
}
print!("* *");
j += 1;
}
print!("\n\n");
}
fn space(size: i32)
{
let mut i: i32 = 0;
while i < size
{
print!(" ");
i += 1;
}
}``````

Output

``````Size : 6 N : 1

* *         * *
*     *
*     *
*     *
*     *
* *

Size : 7 N : 3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Size : 3 N : 4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````package main
import "fmt"
// Go Program
// Program For Sine-Wave Pattern Set-B
type MyPattern struct {}
func getMyPattern() * MyPattern {
var me *MyPattern = &MyPattern {}
return me
}
// include space
func(this MyPattern) space(size int) {
for i := 0 ; i < size ; i++ {
fmt.Print(" ")
}
}
func(this MyPattern) showPattern(hight, width int) {
if hight <= 2 {
return
}
// Display given Height Width
fmt.Print("Height : ", hight,
" Width : ", width, "\n\n")
//First layer of sine wave
for j := 0 ; j <= width ; j++ {
if j == 0 {
fmt.Print(" * *")
} else {
this.space(9)
fmt.Print("* *")
}
}
fmt.Print("\n")
// Intermediate layer of sine wave
for i := 0 ; i < hight - 2 ; i++ {
for j := 0 ; j < width ; j++ {
this.space(5)
fmt.Print("*")
this.space(5)
fmt.Print("*")
}
fmt.Print("\n")
}
//Last layer of sine wave
for j := 0 ; j < width ; j++ {
if j == 0 {
this.space(7)
} else {
this.space(9)
}
fmt.Print("* *")
}
fmt.Print("\n\n")
}
func main() {
var obj * MyPattern = getMyPattern()
//Test Case
obj.showPattern(6, 1)
obj.showPattern(7, 3)
obj.showPattern(3, 4)
}``````

Output

``````Size : 6 N : 1

* *         * *
*     *
*     *
*     *
*     *
* *

Size : 7 N : 3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Size : 3 N : 4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````//C Program
//Program For Sine-Wave Pattern Set-B
#include <stdio.h>

//include space
void space(int size)
{
for (int i = 0; i < size; ++i)
{
printf(" ");
}
}
void show_pattern(int size, int n)
{
if (size <= 2)
{
return;
}
printf("Size : %d  N : %d\n\n", size, n);
//First layer of sine wave
for (int j = 0; j <= n; ++j)
{
if (j == 0)
{
printf(" * *");
}
else
{
space(9);
printf("* *");
}
}
printf("\n");
// Intermediate layer of sine wave
for (int i = 0; i < size - 2; ++i)
{
for (int j = 0; j < n; ++j)
{
space(5);
printf("*");
space(5);
printf("*");
}
printf("\n");
}
//Last layer of sine wave
for (int j = 0; j < n; ++j)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
printf("* *");
}
printf("\n\n");
}
int main()
{
//Test Case
show_pattern(6, 1);
show_pattern(7, 3);
show_pattern(3, 4);
return 0;
}``````

Output

``````Size : 6  N : 1

* *         * *
*     *
*     *
*     *
*     *
* *

Size : 7  N : 3

* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Size : 3  N : 4

* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````
``````//C Program
//Program For Sine-Wave Pattern Set-C
#include <stdio.h>

void space(int size)
{
for (int i = 0; i < size; ++i)
{
printf(" ");
}
}
void show_pattern(int size, int n)
{
if (size <= 2)
{
return;
}
printf("Size : %d  N : %d\n\n", size, n);
int i = 0;
int j = 0;
//First layer of first sine wave
for (j = 0; j < n; ++j)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
printf("✰ ✰");
}
printf("\n");
// Intermediate layer of first sine wave
for (i = 0; i < size - 2; ++i)
{
for (j = 0; j < n; ++j)
{
space(5);
printf("✰");
space(5);
printf("✰");
}
printf("\n");
}
//Last layer of sine wave
for (j = 0; j <= n; ++j)
{
if (j == 0)
{
printf(" ✰ ✰");
}
else
{
space(9);
printf("✰ ✰");
}
}
printf("\n");
//Display bottom layer
//First layer of second sine wave
for (j = 0; j <= n; ++j)
{
if (j == 0)
{
printf(" ✰ ✰");
}
else
{
space(9);
printf("✰ ✰");
}
}
printf("\n");
// Intermediate layer of second sine wave
for (i = 0; i < size - 2; ++i)
{
for (j = 0; j < n; ++j)
{
space(5);
printf("✰");
space(5);
printf("✰");
}
printf("\n");
}
//Last layer of second sine wave
for (j = 0; j < n; ++j)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
printf("✰ ✰");
}
printf("\n\n");
}
int main()
{
//Test Case
show_pattern(6, 1);
show_pattern(7, 3);
show_pattern(3, 4);
return 0;
}``````

Output

``````Size : 6  N : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Size : 7  N : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Size : 3  N : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````// Java Program
// Program For Sine-Wave Pattern Set-C
class MyPattern
{
// include space
public void space(int size)
{
for (int i = 0; i < size; ++i)
{
System.out.print(" ");
}
}
public void showPattern(int height, int width)
{
if (height <= 2)
{
return;
}
System.out.print("Height : " + height +
" Width : " + width + "\n\n");
int i = 0;
int j = 0;
//First layer of first sine wave
for (j = 0; j < width; ++j)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
System.out.print("✰ ✰");
}
System.out.print("\n");
// Intermediate layer of first sine wave
for (i = 0; i < height - 2; ++i)
{
for (j = 0; j < width; ++j)
{
space(5);
System.out.print("✰");
space(5);
System.out.print("✰");
}
System.out.print("\n");
}
//Last layer of sine wave
for (j = 0; j <= width; ++j)
{
if (j == 0)
{
System.out.print(" ✰ ✰");
}
else
{
space(9);
System.out.print("✰ ✰");
}
}
System.out.print("\n");
//Display bottom layer
//First layer of second sine wave
for (j = 0; j <= width; ++j)
{
if (j == 0)
{
System.out.print(" ✰ ✰");
}
else
{
space(9);
System.out.print("✰ ✰");
}
}
System.out.print("\n");
// Intermediate layer of second sine wave
for (i = 0; i < height - 2; ++i)
{
for (j = 0; j < width; ++j)
{
space(5);
System.out.print("✰");
space(5);
System.out.print("✰");
}
System.out.print("\n");
}
//Last layer of second sine wave
for (j = 0; j < width; ++j)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
System.out.print("✰ ✰");
}
System.out.print("\n\n");
}
public static void main(String[] args)
{
MyPattern task = new MyPattern();
// Test
task.showPattern(6, 1);
task.showPattern(7, 3);
task.showPattern(3, 4);
}
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````// Include header file
#include <iostream>
using namespace std;
// C++ Program
// Program For Sine-Wave Pattern Set-C
class MyPattern
{
public:
// include space
void space(int size)
{
for (int i = 0; i < size; ++i)
{
cout << " ";
}
}
void showPattern(int height, int width)
{
if (height <= 2)
{
return;
}
cout << "Height : " << height
<< " Width : " << width << "\n\n";
int i = 0;
int j = 0;
//First layer of first sine wave
for (j = 0; j < width; ++j)
{
if (j == 0)
{
this->space(7);
}
else
{
this->space(9);
}
cout << "✰ ✰";
}
cout << "\n";
// Intermediate layer of first sine wave
for (i = 0; i < height - 2; ++i)
{
for (j = 0; j < width; ++j)
{
this->space(5);
cout << "✰";
this->space(5);
cout << "✰";
}
cout << "\n";
}
//Last layer of sine wave
for (j = 0; j <= width; ++j)
{
if (j == 0)
{
cout << " ✰ ✰";
}
else
{
this->space(9);
cout << "✰ ✰";
}
}
cout << "\n";
//Display bottom layer
//First layer of second sine wave
for (j = 0; j <= width; ++j)
{
if (j == 0)
{
cout << " ✰ ✰";
}
else
{
this->space(9);
cout << "✰ ✰";
}
}
cout << "\n";
// Intermediate layer of second sine wave
for (i = 0; i < height - 2; ++i)
{
for (j = 0; j < width; ++j)
{
this->space(5);
cout << "✰";
this->space(5);
cout << "✰";
}
cout << "\n";
}
//Last layer of second sine wave
for (j = 0; j < width; ++j)
{
if (j == 0)
{
this->space(7);
}
else
{
this->space(9);
}
cout << "✰ ✰";
}
cout << "\n\n";
}
};
int main()
{
MyPattern *task = new MyPattern();
// Test
task->showPattern(6, 1);
task->showPattern(7, 3);
task->showPattern(3, 4);
return 0;
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````// Include namespace system
using System;
// Csharp Program
// Program For Sine-Wave Pattern Set-C
public class MyPattern
{
// include space
public void space(int size)
{
for (int i = 0; i < size; ++i)
{
Console.Write(" ");
}
}
public void showPattern(int height, int width)
{
if (height <= 2)
{
return;
}
Console.Write("Height : " + height +
" Width : " + width + "\n\n");
int i = 0;
int j = 0;
//First layer of first sine wave
for (j = 0; j < width; ++j)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
Console.Write("✰ ✰");
}
Console.Write("\n");
// Intermediate layer of first sine wave
for (i = 0; i < height - 2; ++i)
{
for (j = 0; j < width; ++j)
{
this.space(5);
Console.Write("✰");
this.space(5);
Console.Write("✰");
}
Console.Write("\n");
}
//Last layer of sine wave
for (j = 0; j <= width; ++j)
{
if (j == 0)
{
Console.Write(" ✰ ✰");
}
else
{
this.space(9);
Console.Write("✰ ✰");
}
}
Console.Write("\n");
//Display bottom layer
//First layer of second sine wave
for (j = 0; j <= width; ++j)
{
if (j == 0)
{
Console.Write(" ✰ ✰");
}
else
{
this.space(9);
Console.Write("✰ ✰");
}
}
Console.Write("\n");
// Intermediate layer of second sine wave
for (i = 0; i < height - 2; ++i)
{
for (j = 0; j < width; ++j)
{
this.space(5);
Console.Write("✰");
this.space(5);
Console.Write("✰");
}
Console.Write("\n");
}
//Last layer of second sine wave
for (j = 0; j < width; ++j)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
Console.Write("✰ ✰");
}
Console.Write("\n\n");
}
public static void Main(String[] args)
{
MyPattern task = new MyPattern();
// Test
task.showPattern(6, 1);
task.showPattern(7, 3);
task.showPattern(3, 4);
}
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````<?php
// Php Program
// Program For Sine-Wave Pattern Set-C
class MyPattern
{
// include space
public  function space(\$size)
{
for (\$i = 0; \$i < \$size; ++\$i)
{
echo(" ");
}
}
public  function showPattern(\$height, \$width)
{
if (\$height <= 2)
{
return;
}
echo("Height : ".\$height.
" Width : ".\$width.
"\n\n");
\$i = 0;
\$j = 0;
//First layer of first sine wave
for (\$j = 0; \$j < \$width; ++\$j)
{
if (\$j == 0)
{
\$this->space(7);
}
else
{
\$this->space(9);
}
echo("✰ ✰");
}
echo("\n");
// Intermediate layer of first sine wave
for (\$i = 0; \$i < \$height - 2; ++\$i)
{
for (\$j = 0; \$j < \$width; ++\$j)
{
\$this->space(5);
echo("✰");
\$this->space(5);
echo("✰");
}
echo("\n");
}
//Last layer of sine wave
for (\$j = 0; \$j <= \$width; ++\$j)
{
if (\$j == 0)
{
echo(" ✰ ✰");
}
else
{
\$this->space(9);
echo("✰ ✰");
}
}
echo("\n");
//Display bottom layer
//First layer of second sine wave
for (\$j = 0; \$j <= \$width; ++\$j)
{
if (\$j == 0)
{
echo(" ✰ ✰");
}
else
{
\$this->space(9);
echo("✰ ✰");
}
}
echo("\n");
// Intermediate layer of second sine wave
for (\$i = 0; \$i < \$height - 2; ++\$i)
{
for (\$j = 0; \$j < \$width; ++\$j)
{
\$this->space(5);
echo("✰");
\$this->space(5);
echo("✰");
}
echo("\n");
}
//Last layer of second sine wave
for (\$j = 0; \$j < \$width; ++\$j)
{
if (\$j == 0)
{
\$this->space(7);
}
else
{
\$this->space(9);
}
echo("✰ ✰");
}
echo("\n\n");
}
}

function main()
{
\$task = new MyPattern();
// Test
\$task->showPattern(6, 1);
\$task->showPattern(7, 3);
\$task->showPattern(3, 4);
}
main();``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````// Node JS Program
// Program For Sine-Wave Pattern Set-C
class MyPattern
{
// include space
space(size)
{
for (var i = 0; i < size; ++i)
{
process.stdout.write(" ");
}
}
showPattern(height, width)
{
if (height <= 2)
{
return;
}
process.stdout.write("Height : " + height +
" Width : " + width + "\n\n");
var i = 0;
var j = 0;
//First layer of first sine wave
for (j = 0; j < width; ++j)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
process.stdout.write("✰ ✰");
}
process.stdout.write("\n");
// Intermediate layer of first sine wave
for (i = 0; i < height - 2; ++i)
{
for (j = 0; j < width; ++j)
{
this.space(5);
process.stdout.write("✰");
this.space(5);
process.stdout.write("✰");
}
process.stdout.write("\n");
}
//Last layer of sine wave
for (j = 0; j <= width; ++j)
{
if (j == 0)
{
process.stdout.write(" ✰ ✰");
}
else
{
this.space(9);
process.stdout.write("✰ ✰");
}
}
process.stdout.write("\n");
//Display bottom layer
//First layer of second sine wave
for (j = 0; j <= width; ++j)
{
if (j == 0)
{
process.stdout.write(" ✰ ✰");
}
else
{
this.space(9);
process.stdout.write("✰ ✰");
}
}
process.stdout.write("\n");
// Intermediate layer of second sine wave
for (i = 0; i < height - 2; ++i)
{
for (j = 0; j < width; ++j)
{
this.space(5);
process.stdout.write("✰");
this.space(5);
process.stdout.write("✰");
}
process.stdout.write("\n");
}
//Last layer of second sine wave
for (j = 0; j < width; ++j)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
process.stdout.write("✰ ✰");
}
process.stdout.write("\n\n");
}
}

function main()
{
var task = new MyPattern();
// Test
task.showPattern(6, 1);
task.showPattern(7, 3);
task.showPattern(3, 4);
}
main();``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````#  Python 3 Program
#  Program For Sine-Wave Pattern Set-C
class MyPattern :
#  include space
def space(self, size) :
i = 0
while (i < size) :
print(" ", end = "")
i += 1

def showPattern(self, height, width) :
if (height <= 2) :
return

print("Height : ", height ,
" Width : ", width ,"\n")
i = 0
j = 0
j = 0
# First layer of first sine wave
while (j < width) :
if (j == 0) :
self.space(7)
else :
self.space(9)

print("✰ ✰", end = "")
j += 1

print(end = "\n")
i = 0
#  Intermediate layer of first sine wave
while (i < height - 2) :
j = 0
while (j < width) :
self.space(5)
print("✰", end = "")
self.space(5)
print("✰", end = "")
j += 1

print(end = "\n")
i += 1

j = 0
# Last layer of sine wave
while (j <= width) :
if (j == 0) :
print(" ✰ ✰", end = "")
else :
self.space(9)
print("✰ ✰", end = "")

j += 1

print(end = "\n")
j = 0
# Display bottom layer
# First layer of second sine wave
while (j <= width) :
if (j == 0) :
print(" ✰ ✰", end = "")
else :
self.space(9)
print("✰ ✰", end = "")

j += 1

print(end = "\n")
i = 0
#  Intermediate layer of second sine wave
while (i < height - 2) :
j = 0
while (j < width) :
self.space(5)
print("✰", end = "")
self.space(5)
print("✰", end = "")
j += 1

print(end = "\n")
i += 1

j = 0
# Last layer of second sine wave
while (j < width) :
if (j == 0) :
self.space(7)
else :
self.space(9)

print("✰ ✰", end = "")
j += 1

print("\n")

def main() :
task = MyPattern()
#  Test
task.showPattern(6, 1)
task.showPattern(7, 3)
task.showPattern(3, 4)

if __name__ == "__main__": main()``````

Output

``````Height :  6  Width :  1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Height :  7  Width :  3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Height :  3  Width :  4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````#  Ruby Program
#  Program For Sine-Wave Pattern Set-C
class MyPattern
#  include space
def space(size)
i = 0
while (i < size)
print(" ")
i += 1
end

end

def showPattern(height, width)
if (height <= 2)
return
end

print("Height : ", height ,
" Width : ", width ,"\n\n")
i = 0
j = 0
# First layer of first sine wave
while (j < width)
if (j == 0)
self.space(7)
else

self.space(9)
end

print("✰ ✰")
j += 1
end

print("\n")
i = 0
#  Intermediate layer of first sine wave
while (i < height - 2)
j = 0
while (j < width)
self.space(5)
print("✰")
self.space(5)
print("✰")
j += 1
end

print("\n")
i += 1
end

j = 0
# Last layer of sine wave
while (j <= width)
if (j == 0)
print(" ✰ ✰")
else

self.space(9)
print("✰ ✰")
end

j += 1
end

print("\n")
j = 0
# Display bottom layer
# First layer of second sine wave
while (j <= width)
if (j == 0)
print(" ✰ ✰")
else

self.space(9)
print("✰ ✰")
end

j += 1
end

print("\n")
i = 0
#  Intermediate layer of second sine wave
while (i < height - 2)
j = 0
while (j < width)
self.space(5)
print("✰")
self.space(5)
print("✰")
j += 1
end

print("\n")
i += 1
end

j = 0
# Last layer of second sine wave
while (j < width)
if (j == 0)
self.space(7)
else

self.space(9)
end

print("✰ ✰")
j += 1
end

print("\n\n")
end

end

def main()
task = MyPattern.new()
#  Test
task.showPattern(6, 1)
task.showPattern(7, 3)
task.showPattern(3, 4)
end

main()``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰

``````
``````// Scala Program
// Program For Sine-Wave Pattern Set-C
class MyPattern()
{
// include space
def space(size: Int): Unit = {
var i: Int = 0;
while (i < size)
{
print(" ");
i += 1;
}
}
def showPattern(height: Int, width: Int): Unit = {
if (height <= 2)
{
return;
}
print("Height : " + height +
" Width : " + width + "\n\n");
var i: Int = 0;
var j: Int = 0;
//First layer of first sine wave
while (j < width)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
print("✰ ✰");
j += 1;
}
print("\n");
i = 0;
// Intermediate layer of first sine wave
while (i < height - 2)
{
j = 0;
while (j < width)
{
space(5);
print("✰");
space(5);
print("✰");
j += 1;
}
print("\n");
i += 1;
}
j = 0;
//Last layer of sine wave
while (j <= width)
{
if (j == 0)
{
print(" ✰ ✰");
}
else
{
space(9);
print("✰ ✰");
}
j += 1;
}
print("\n");
j = 0;
//Display bottom layer
//First layer of second sine wave
while (j <= width)
{
if (j == 0)
{
print(" ✰ ✰");
}
else
{
space(9);
print("✰ ✰");
}
j += 1;
}
print("\n");
i = 0;
// Intermediate layer of second sine wave
while (i < height - 2)
{
j = 0;
while (j < width)
{
space(5);
print("✰");
space(5);
print("✰");
j += 1;
}
print("\n");
i += 1;
}
j = 0;
//Last layer of second sine wave
while (j < width)
{
if (j == 0)
{
space(7);
}
else
{
space(9);
}
print("✰ ✰");
j += 1;
}
print("\n\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: MyPattern = new MyPattern();
// Test
task.showPattern(6, 1);
task.showPattern(7, 3);
task.showPattern(3, 4);
}
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````// Swift 4 Program
// Program For Sine-Wave Pattern Set-C
class MyPattern
{
// include space
func space(_ size: Int)
{
var i: Int = 0;
while (i < size)
{
print(" ", terminator: "");
i += 1;
}
}
func showPattern(_ height: Int, _ width: Int)
{
if (height <= 2)
{
return;
}
print("Height : ", height ,
" Width : ", width ,"\n");
var i: Int = 0;
var j: Int = 0;

//First layer of first sine wave
while (j < width)
{
if (j == 0)
{
self.space(7);
}
else
{
self.space(9);
}
print("✰ ✰", terminator: "");
j += 1;
}
print(terminator: "\n");
i = 0;
// Intermediate layer of first sine wave
while (i < height - 2)
{
j = 0;
while (j < width)
{
self.space(5);
print("✰", terminator: "");
self.space(5);
print("✰", terminator: "");
j += 1;
}
print(terminator: "\n");
i += 1;
}
j = 0;
//Last layer of sine wave
while (j <= width)
{
if (j == 0)
{
print(" ✰ ✰", terminator: "");
}
else
{
self.space(9);
print("✰ ✰", terminator: "");
}
j += 1;
}
print(terminator: "\n");
j = 0;
//Display bottom layer
//First layer of second sine wave
while (j <= width)
{
if (j == 0)
{
print(" ✰ ✰", terminator: "");
}
else
{
self.space(9);
print("✰ ✰", terminator: "");
}
j += 1;
}
print(terminator: "\n");
i = 0;
// Intermediate layer of second sine wave
while (i < height - 2)
{
j = 0;
while (j < width)
{
self.space(5);
print("✰", terminator: "");
self.space(5);
print("✰", terminator: "");
j += 1;
}
print(terminator: "\n");
i += 1;
}
j = 0;
//Last layer of second sine wave
while (j < width)
{
if (j == 0)
{
self.space(7);
}
else
{
self.space(9);
}
print("✰ ✰", terminator: "");
j += 1;
}
print("\n");
}
}
func main()
{
let task: MyPattern = MyPattern();
// Test
task.showPattern(6, 1);
task.showPattern(7, 3);
task.showPattern(3, 4);
}
main();``````

Output

``````Height :  6  Width :  1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Height :  7  Width :  3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Height :  3  Width :  4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````// Kotlin Program
// Program For Sine-Wave Pattern Set-C
class MyPattern
{
// include space
fun space(size: Int): Unit
{
var i: Int = 0;
while (i < size)
{
print(" ");
i += 1;
}
}
fun showPattern(height: Int, width: Int): Unit
{
if (height <= 2)
{
return;
}
print("Height : " + height +
" Width : " + width + "\n\n");
var i: Int ;
var j: Int = 0;
//First layer of first sine wave
while (j < width)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
print("✰ ✰");
j += 1;
}
print("\n");
i = 0;
// Intermediate layer of first sine wave
while (i < height - 2)
{
j = 0;
while (j < width)
{
this.space(5);
print("✰");
this.space(5);
print("✰");
j += 1;
}
print("\n");
i += 1;
}
j = 0;
//Last layer of sine wave
while (j <= width)
{
if (j == 0)
{
print(" ✰ ✰");
}
else
{
this.space(9);
print("✰ ✰");
}
j += 1;
}
print("\n");
j = 0;
//Display bottom layer
//First layer of second sine wave
while (j <= width)
{
if (j == 0)
{
print(" ✰ ✰");
}
else
{
this.space(9);
print("✰ ✰");
}
j += 1;
}
print("\n");
i = 0;
// Intermediate layer of second sine wave
while (i < height - 2)
{
j = 0;
while (j < width)
{
this.space(5);
print("✰");
this.space(5);
print("✰");
j += 1;
}
print("\n");
i += 1;
}
j = 0;
//Last layer of second sine wave
while (j < width)
{
if (j == 0)
{
this.space(7);
}
else
{
this.space(9);
}
print("✰ ✰");
j += 1;
}
print("\n\n");
}
}
fun main(args: Array < String > ): Unit
{
val task: MyPattern = MyPattern();
// Test
task.showPattern(6, 1);
task.showPattern(7, 3);
task.showPattern(3, 4);
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````package main
import "fmt"
// Go Program
// Program For Sine-Wave Pattern Set-C
type MyPattern struct {}
func getMyPattern() * MyPattern {
var me *MyPattern = &MyPattern {}
return me
}
// include space
func(this MyPattern) space(size int) {
for i := 0 ; i < size ; i++ {
fmt.Print(" ")
}
}
func(this MyPattern) showPattern(height, width int) {
if height <= 2 {
return
}
fmt.Print("Height : ", height,
" Width : ", width, "\n\n")
var i int = 0
var j int = 0
//First layer of first sine wave
for j = 0 ; j < width ; j++ {
if j == 0 {
this.space(7)
} else {
this.space(9)
}
fmt.Print("✰ ✰")
}
fmt.Print("\n")
// Intermediate layer of first sine wave
for i = 0 ; i < height - 2 ; i++ {
for j = 0 ; j < width ; j++ {
this.space(5)
fmt.Print("✰")
this.space(5)
fmt.Print("✰")
}
fmt.Print("\n")
}
//Last layer of sine wave
for j = 0 ; j <= width ; j++ {
if j == 0 {
fmt.Print(" ✰ ✰")
} else {
this.space(9)
fmt.Print("✰ ✰")
}
}
fmt.Print("\n")
//Display bottom layer
//First layer of second sine wave
for j = 0 ; j <= width ; j++ {
if j == 0 {
fmt.Print(" ✰ ✰")
} else {
this.space(9)
fmt.Print("✰ ✰")
}
}
fmt.Print("\n")
// Intermediate layer of second sine wave
for i = 0 ; i < height - 2 ; i++ {
for j = 0 ; j < width ; j++ {
this.space(5)
fmt.Print("✰")
this.space(5)
fmt.Print("✰")
}
fmt.Print("\n")
}
//Last layer of second sine wave
for j = 0 ; j < width ; j++ {
if j == 0 {
this.space(7)
} else {
this.space(9)
}
fmt.Print("✰ ✰")
}
fmt.Print("\n\n")
}
func main() {
var task * MyPattern = getMyPattern()
// Test
task.showPattern(6, 1)
task.showPattern(7, 3)
task.showPattern(3, 4)
}``````

Output

``````Height : 6 Width : 1

✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰         ✰ ✰
✰ ✰         ✰ ✰
✰     ✰
✰     ✰
✰     ✰
✰     ✰
✰ ✰

Height : 7 Width : 3

✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰

Height : 3 Width : 4

✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
✰     ✰     ✰     ✰     ✰     ✰     ✰     ✰
✰ ✰         ✰ ✰         ✰ ✰         ✰ ✰
``````
``````//C Program
//Program For Sine-Wave Pattern Set-C
fn main()
{
//Test Case
show_pattern(6, 1);
show_pattern(7, 3);
show_pattern(3, 4);
}
fn show_pattern(size: i32, n: i32)
{
if size <= 2
{
return;
}
print!("Size : {} N : {}\n\n", size, n);
let mut i: i32 = 0;
let mut j: i32 = 0;
//First layer of first sine wave
while j < n
{
if j == 0
{
space(7);
}
else
{
space(9);
}
print!("* *");
j += 1;
}
print!("\n");
// Intermediate layer of first sine wave
while i < size - 2
{
j = 0;
while j < n
{
space(5);
print!("*");
space(5);
print!("*");
j += 1;
}
print!("\n");
i += 1;
}
j = 0;
//Last layer of sine wave
while j <= n
{
if j == 0
{
print!(" * *");
}
else
{
space(9);
print!("* *");
}
j += 1;
}
print!("\n");
j = 0;
//Display bottom layer
//First layer of second sine wave
while j <= n
{
if j == 0
{
print!(" * *");
}
else
{
space(9);
print!("* *");
}
j += 1;
}
print!("\n");
i = 0;
// Intermediate layer of second sine wave
while i < size - 2
{
j = 0;
while j < n
{
space(5);
print!("*");
space(5);
print!("*");
j += 1;
}
print!("\n");
i += 1;
}
j = 0;
//Last layer of second sine wave
while j < n
{
if j == 0
{
space(7);
}
else
{
space(9);
}
print!("* *");
j += 1;
}
print!("\n\n");
}
fn space(size: i32)
{
let mut i: i32 = 0;
while i < size
{
print!(" ");
i += 1;
}
}``````

Output

``````Size : 6 N : 1

* *
*     *
*     *
*     *
*     *
* *         * *
* *         * *
*     *
*     *
*     *
*     *
* *

Size : 7 N : 3

* *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *         * *
* *         * *         * *         * *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
*     *     *     *     *     *
* *         * *         * *

Size : 3 N : 4

* *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *         * *
* *         * *         * *         * *         * *
*     *     *     *     *     *     *     *
* *         * *         * *         * *
``````

Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

Categories
Relative Post