Ad Code

NEW POST

6/recent/ticker-posts

HOW TO PRINT ALPHABET R IN STARS * PATTERNS? VERY SIMPLE LOGIC!!

OUTPUT:

*******                                                                         

*          *                                                                         

                                                                                

*          *                                                                         

                                                                                

*         *                                                                         

                                                                                

*         *                                                                         

                                                                                

*         *                                                                         

*         *                                                                      

*******                                                                         

*                                                                              

      *                                                                               

*                                                                             

             *                                                                               

*                                                                            

*                      *        


CONCEPT:

FIRST, define two loops I for rows and j for columns now  define I and then define J loop print horizontal lines in R. now define another loop for let suppose 'k' for the lower part of R and put in if condition for print respective patterns you can take help for below code to understand better 


C CODE(RUNS ON TURBO C++): 

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,k;

clrscr();

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

{

for(j=1;j<=1;j++)

{

printf("*");

}

    for(k=1;k<=6;k++)

{

if(i==1||i==7||i>=2&&i<=6&&k==6)

{

printf("*");

}

else

{

printf(" ");

}

}


     printf("\n");

    for(k=6;k<=9;k++)

    {

    if(i==k)

    {

    printf("*");

    }

    else

    {

    printf(" ");

    }

    }

    printf("\n");


}

getch();

}

Post a Comment

0 Comments