patternprogram_342 softethics

Pattern 342

C

#include <stdio.h>

int main()
{
  int i,j;
  int n=7;//size

  for(i=0; i<n; i++)
  {
    for(j=0; j<n; j++)
    {
      if(    i==0 || j==0 || i==j || i==n-1 || j==n-1 ||  i+j == n-
             1)
      {
        printf("* ");
      }
      else
      {
        printf("  ");
      }
    }
    printf("\n");
  }
}

C++

 #include<iostream.h>
 
 int main()
 {
  int i,j;
  int n=7;//size
 
  for(i=0;i<n;i++)
  {
   for(j=0;j<n;j++)
   {
     if(    i==0 || j==0 || i==j || i==n-1 || j==n-1 ||  i+j == n-
      1)
     {
      cout<<"* ";
     }
     else
     {
      cout<<"  ";
     }
   }
   cout<<"\n";
  }
 }

Java

 class PatternProg
 {
     public static void main(String args[])
     {
      int i;
      int j;
      int n = 7; //size
 
      for (i = 0;i < n;i++)
      {
       for (j = 0;j < n;j++)
       {
         if (i == 0 || j == 0 || i == j || i == n - 1 || j == n - 
       1 || i + j == n - 1)
         {
          System.out.print("* ");
         }
         else
         {
          System.out.print("  ");
         }
       }
       System.out.println();
      }
     }
 }

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int i;
    int j;
    int n = 7; //size

    for (i = 0; i < n; i++)
    {
      for (j = 0; j < n; j++)
      {
        if (i == 0 || j == 0 || i == j || i == n - 1 || j == n - 1 || i + j == n - 1)
        {
          Console.Write("* "); // * after spaces
        }
        else
        {
          Console.Write("  "); // 2 spaces
        }
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

n = 7  # size
for x in range(0, n):
    for y in range(0, n):
        if (x == 0 or y == 0 or x == y or x == n - 1 or y == n - 1 or x + y == n - 1):
            print("* ", end="")  # *space
        else:
            print("  ", end="")  # two spaces
    print()
5 1 vote
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments