Pattern 329

Pattern 329 post thumbnail image

C

#include <stdio.h>
#include <conio.h>
int main()
{
  int i,j;


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

C++

 #include <iostream.h>
 #include <conio.h>
 int main()
 {
 int i,j;
 
 
 for(i=1; i<=5; i++)
 {
  for(j=1;j<=5;j++)
  {
   if(j==3||i==3)
    cout<<"* ";
   else
    cout<<"  ";
  }
  cout<<endl;
 }
  return 0;
 }

Java

 class PatternProg
 {
     public static void main(String a[])
     {
     
     for (int i = 1; i <= 5; i++)
     {
      for (int j = 1;j <= 5;j++)
      {
       if (j == 3 || i == 3)
       {
        System.out.print("* ");
       }
       else
       {
        System.out.print("  ");
       }
      }
      System.out.print("\n");
     }
     
     }
 }

C#

using System;

class PatternProg
{
  public static void Main(string[] a)
  {

    for (int i = 1; i <= 5; i++)
    {
      for (int j = 1; j <= 5; j++)
      {
        if (j == 3 || i == 3)
        {
          Console.Write("* "); // space after *
        }
        else
        {
          Console.Write("  "); // 2 spaces
        }
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  }
}

Python

n = 5  # size
cen = n // 2 + 1  # centre
for x in range(1, n + 1):
    for y in range(1, n + 1):
        if (x == cen or y == cen):
            print("* ", end="")
        else:
            print("  ", end="")
    print()
5 2 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Patterns