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("x ");
else
printf("o ");
}
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<<"x ";
else
cout<<"o ";
}
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("x ");
}
else
{
System.out.print("o ");
}
}
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("x ");
}
else
{
Console.Write("o ");
}
}
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("x ", end="")
else:
print("o ", end="")
print()