Pattern Printing

Hi friends.. After a long time i am here back with program codes now. today i am going to write a program for pattern printing. I am writing code to print the following pattern:



Code to print this pattern is: 


#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
i=1;
while(i<=13)
{
if(i<=4)
{
k=3;
   while(k>=i)
    {
      printf(" ");
      k--;
    }
     j=1;
     while(j<=i)
     {
      printf("* ");
      j++;

     }
 }
 if(i>4 && i<=7)
 {
  k=5;
  while(k<=i)
  {
  printf(" ");
  k++;
  }
  j=7;
  while(j>=i)
  {
  printf("* ");
  j--;
  }
  }
  if(i>7 && i<=10)
  {
   k=9;
   while(k>=i)
   {
   printf(" ");
   k--;
   }
   j=7;
   while(j<=i)
   {
   printf("* ");
   j++;
   }
   }
   if(i>10)
   {
   k=11;
   while(k<=i)
   {
   printf(" ");
   k++;
   }
   j=13;
   while(j>=i)
   {
   printf("* ");
   j--;
   }
   }
i++;
printf("\n");
}
getch();
}

Comments

  1. Pattern printing programs in C are very nice examples of loops for new programmers. It helps in learning the fundamental of loops and Input and output in C programming language.

    ReplyDelete

Post a Comment

Popular posts from this blog

Components of C language

Decision making using if statement

How to make payment for final certificate, migration, provisional for the students of last semester of ptu?