Pattern 341

Pattern 341 post thumbnail image

C

#include<stdio.h>

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

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

C++

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

Java

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

C#

using System;

class PatternProg
{
  public static void Main()
  {
    int n = 5; //size
    for (int i = 1; i <= n; i++)
    {
      for (int j = 1; j <= n; j++)
      {
        if ((j == 1 || j == n) || (i == 1 || i == n))
        {
          Console.Write("*"); //ANY SYMBOL
        }
        else
        {
          Console.Write("#"); //ANY SYMBOL
        }
      }
      Console.WriteLine();
    }
    Console.ReadKey(true);
  } //end of main
} //end of class

Python

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

Related Patterns