Pattern Program T-02

C

#include<stdio.h>

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

  for(i=1; i <= n; i++) 
  { 
    for(j=1; j <=n; j++) 
    { 
      if(i<=n/2) // upper part
      {
	    if(j < n/2) 
          printf(" "); 
        else if(j<(n/2)+i)
          printf("*");   
      }
	  else  // lower part
	  {
        if(i-(n/2)>j)
          printf(" "); 
     	else if(i<=j)
	      printf("*"); 
	  }
    } 
    printf("\n"); 
  } 
  return 0; 
} 

C++

#include<iostream.h>

int main() 
{ 
  int n = 12;  // even size 


  for(int i=1; i <= n; i++) 
  { 
    for(int j=1; j <=n; j++) 
    { 
      if(i<=n/2) // upper part
      {
	    if(j < n/2) 
          cout<<" ";
	    else if(j<(n/2)+i)
     	  cout<<"*";   
      }
	  else  // lower part
	  {
        if(i-(n/2)>j)
    	  cout<<" "; 
		else if(i<=j)
    	  cout<<"*";  
      }
	  
	  
    } 
    cout<<endl;
  } 
  return 0; 
} 

Java

class PatternProg
{
   public static void main (String args[])
   {
     int n = 12;  // even size

     for(int i=1; i <= n; i++)
     {
       for(int j=1; j <=n; j++)
       {
         if(i<=n/2) // upper part
         {
           if(j < n/2)
             System.out.print(" ");
           else if(j<(n/2)+i)
             System.out.print("*");
        }
        else  // lower part
        {
           if(i-(n/2)>j)
             System.out.print(" ");
           else if(i<=j)
             System.out.print("*");
       }
    }
    System.out.println();
  }
 }
}

C#

Python

5 1 vote
Rate this Program
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments