Ad Code

NEW POST

6/recent/ticker-posts

HOW TO PRINT 'Z' IN STARS * PATTER ? VERY SIMPLE LOGIC!!

OUTPUT:



CONCEPT:

To print Z first print horizontal lines of Z as per condition and the main problem is to print diagonal elements (means star) so for that, we can use if(i==j).

for better understanding refer below code

 

 C CODE(RUNS ON TURBO C++):

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int i,j;

for(i=1;i<=5;i++)

{

for(j=5;j>=1;j--)

{

if(i==j||i==1||i==5)

{

printf("*");

}

else

{

printf(" ");

}

}

printf("\n");

}


getch();

}

Post a Comment

0 Comments