patternprogram_337 softethics

Pattern 337

C

#include<stdio.h>

int main()
{
  int i,j;

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

C++

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

Java

 class PatternProg
 {
     public static void main(String args[])
     {
 int n=5; //size
 int m=(n/2)+1;   //center
 for(int i=1;i<=n;i++){
 for(int j=1;j<=n;j++)
 {
 if(i==m&&j==m)
 System.out.print("o"); 
 else
 System.out.print("x"); 
 }
 System.out.println();
 }
     } //end of main
 }  //end of class

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int n = 5; //size
    int m = (n / 2) + 1; //center
    for (int i = 1; i <= n; i++)
    {
      for (int j = 1; j <= n; j++)
      {
        if (i == m && j == m)
        {
          Console.Write("o ");
        }
        else
        {
          Console.Write("x ");
        }
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  } //end of main
} //end of class

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 and y == cen):
            print("x", end="")
        else:
            print("o", end="")
    print()
0 0 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments