Pattern Program T-02

Pattern Program T-02 post thumbnail image

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

3 2 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related Patterns