# Programs to print Interesting Patterns

Program to print following pattern:
Examples:

```Input : 5
Output:
* * * * *  * * * * *
* * * *      * * * *
* * *          * * *
* *              * *
*                  *
*                  *
* *              * *
* * *          * * *
* * * *      * * * *
* * * * *  * * * * *
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

This program is divided into four parts.

## C

```// C program to print
// the given pattern

#include<stdio.h>
pattern(int n)
{
int i,j;

// This is upper half of pattern
for (i=1; i<=n; i++)
{
for (j=1; j<=(2*n); j++)
{
// Left part of pattern
if (i>(n-j+1))
printf(" ");
else
printf("*");

// Right part of pattern
if ((i+n)>j)
printf(" ");
else
printf("*");
}
printf("\n");
}

// This is lower half of pattern
for (i=1; i<=n; i++)
{
for (j=1; j<=(2*n); j++)
{
// Right Part of pattern
if (i<j)
printf(" ");
else
printf("*");

// Left Part of pattern
if (i<=((2*n)-j))
printf(" ");
else
printf("*");
}
printf("\n");
}
}

// main function
int main()
{
pattern(7);
return 0;
}

```

## Java

```// Java program to print
// the given pattern
import java.io.*;

class GFG {

static void pattern(int n)
{
int i, j;

// This is upper half of pattern
for (i = 1; i <= n; i++) {
for (j = 1; j <= (2 * n); j++) {

// Left part of pattern
if (i > (n - j + 1))
System.out.print(" ");
else
System.out.print("*");

// Right part of pattern
if ((i + n) > j)
System.out.print(" ");
else
System.out.print("*");
}

System.out.println("");
}

// This is lower half of pattern
for (i = 1; i <= n; i++) {
for (j = 1; j <= (2 * n); j++) {

// Right Part of pattern
if (i < j)
System.out.print(" ");
else
System.out.print("*");

// Left Part of pattern
if (i <= ((2 * n) - j))
System.out.print(" ");
else
System.out.print("*");
}

System.out.println("");
}
}

// main function
public static void main(String[] args)
{
pattern(7);
}
}

// This code is contributed by vt_m
```

Output:

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

Program to print following pattern:
Examples:

```Input : 5
Output:
*                  *
* *              * *
* * *          * * *
* * * *      * * * *
* * * * *  * * * * *
* * * * *  * * * * *
* * * *      * * * *
* * *          * * *
* *              * *
*                  *
```

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

This program is divided into four parts.

## C

```// C program to print the
// given pattern

#include<stdio.h>
pattern(int n)
{
int i,j;

// This is upper half of pattern
for (i=1; i<=n; i++)
{
for (j=1; j<=(2*n); j++)
{
// Left part of pattern
if (i<j)
printf(" ");
else
printf("*");

// Right part of pattern
if (i<=((2*n)-j))
printf(" ");
else
printf("*");
}
printf("\n");
}

// This is lower half of pattern
for (i=1; i<=n; i++)
{
for (j=1;j<=(2*n);j++)
{
// Left part of pattern
if (i>(n-j+1))
printf(" ");
else
printf("*");

// Right part of pattern
if ((i+n)>j)
printf(" ");
else
printf("*");
}
printf("\n");
}
}

// main function
int main()
{
pattern(7);
return 0;
}

```

## Java

```// Java program to print the
// given pattern

import java.io.*;

class GFG {

static void pattern(int n)
{
int i, j;

// This is upper half of pattern
for (i = 1; i <= n; i++) {
for (j = 1; j <= (2 * n); j++) {

// Left part of pattern
if (i < j)
System.out.print(" ");
else
System.out.print("*");

// Right part of pattern
if (i <= ((2 * n) - j))
System.out.print(" ");
else
System.out.print("*");
}

System.out.println("");
}

// This is lower half of pattern
for (i = 1; i <= n; i++) {
for (j = 1; j <= (2 * n); j++) {

// Left part of pattern
if (i > (n - j + 1))
System.out.print(" ");
else
System.out.print("*");

// Right part of pattern
if ((i + n) > j)
System.out.print(" ");
else
System.out.print("*");
}

System.out.println("");
}
}

// main function
public static void main(String[] args)
{
pattern(7);
}
}

// This code is contributed by vt_m
```

Output:

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