PULCHOWK Pattern

Program


#include<stdio.h>
#include<conio.h>

void main()
{
 /* Storing same string in two different variable in required format 
    is simple hack for question to avoid too many if-else statement 
 */
 char string1[] = "PuLcHoWk";
 char string2[] = "PULCHOWK";
 int i,j, length;
 clrscr();
 /* Pattern */
 for(i=0;i< 8;i++)
 {
  for(j=0;j<=i;j++)
  {
   if(i==3||i==5||i==7)
   {
    putchar(string2[j]);
   }
   else
   {
    putchar(string1[j]);
   }
  }
  putchar('\n');
 }
 getch();
}

Output

P
Pu
PuL
PULC
PuLcH
PULCHO
puLcHoW
PULCHOWK

Alternate Program


#include<stdio.h>
#include<conio.h>

void main()
{
 char string[] = "PuLcHoWk";
 int i,j, length;
 clrscr();
 /* Pattern */
 for(i=0;i<8;i++)
 {
  for(j=0;j<=i;j++)
  {
   if(i==3||i==5||i==7)
   {
    if(string[j]>='a'&&string[j]<='z')
    {
     putchar(string[j]-32);
    }
    else
    {
     putchar(string[j]);
    }
   }
   else
   {
    putchar(string[j]);
   }
  }
  putchar('\n');
 }
 getch();
}