-->

Write a program to get given pattern

/*WAP to get following
                                  * * * * * 
                        * * * * *
                   * * * * * 
             * * * * *
*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
for(i=1;i<=5;i++)      //for number of rows. there are five rows so loop moves fives times
  {
    for(k=8;k>=i;k--)
      {
      printf(" ");   // this part is for space. every time , on display, it decreases space.
      }
    for(j=1;j<=4;j++) //it displays star five times.It displays in columns
      {
 printf("* ");
      }
    printf("\n"););
}
getch();
}
---------------------------
logic in mind:-
----------
it has three parts:
first is number of rows
second part is number of columns
third part decreasing space on each display.
1)fist loop is used for number of rows
2) the inner loop is for space to display
3)the inner most is for star display every time.

Program's screen:-


program's output:


Note:-
From here onward, we are writing program using return and int main().
so using return, it looks like.
#include <stdio.h>
#include<conio.h>
int main()
{
  int i,j,k;
for(i=1;i<=5;i++)      //for number of rows. there are five rows so loop moves fives times
  {
    for(k=8;k>=i;k--)
      {
      printf(" ");   // this part is for space. every time , on display, it decreases space.
      }
    for(j=1;j<=4;j++) //it displays star five times.It displays in columns
      {
 printf("* ");
      }
    printf("\n");
}
   getch();
  return 0;
}
---------------------------------------------------
read me:-

nothing you have to do here. Just put int main() in the beginning and return 0 at the end

wap to display star pattern

/*program to display following

* * * * *
    * * * * *
* * * * *
         * * * * *
             * * * * *

*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
for(i=5;i>=1;i--)      //for number of rows. there are five rows so loop moves fives times
  {
    for(k=i;k<=7;k++)
      {
      printf(" ");   // this part is for space. every time , on display, it increases space.
      }
    for(j=1;j<=5;j++) //it displays star five times.It displays in columns
      {
printf("* ");
      }
    printf("\n");
}
getch();
}
---------------------------
logic in mind:-
----------
it has three parts:
first is number of rows
second part is number of columns
third part increasing space on each display.
1)fist loop is used for number of rows
2) the inner loop is for space to display
3)the inner most is for star display everytime.
------------------------------------------------------
program screenshot


output is






WEAP to display following star pattern

/*program to display following

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
for(i=1;i<=5;i++)      //for number of rows. there are five rows so loop moves fives times
  {
    for(j=1;j<=5;j++) //it displays star five times.It displays in columns
      {
printf("* ");
      }
    printf("\n");
}
getch();
}

------------------------------------
logic in mind:-
1)we have to display five rows and five columns.
2) we have used outer loop five times.
3)and inner loop five times.
-------------------------------
 program 's screenshot





output







write a program to display plus pattern

/*to display following
  +
               +
               +
               +
   + + + + + + + + +
              +
              +
              +
              +
              +
*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char a='+';
int i,j,k=0,k1;
for(i=4;i>=0;i--)
{
  for(k1=-3;k1<=5;k1++)
     {
       printf(" ");
     }
  for(j=1;j<=1;j++)
    {
      printf("%c",a);
    }
  printf("\n");
}
for(i=1;i<=9;i++)
{
for(k1=5;k1<=5;k1++)
     {
       printf(" ");
     }
printf("+");
}
for(i=4;i>=0;i--)
{
  for(k1=-3;k1<=5;k1++)
     {
       printf(" ");
     }
  for(j=1;j<=1;j++)
    {
      printf("%c",a);
    }
  printf("\n");
}
getch();

}
-------------------
logic in mind:-
1)for this display, we have three parts.
      first part is upper 
      second part is horizontal
      third part is vertical form(look circled part)
2) First we display upper part using three loops.
          outer loop is for number of rows
           inner is for space(constant)
          inner most is for display
3) similarly, for second part we have done. ----------------------
program's screenshot:-

----------------------------
program's output:-

WAP to get following alphabetical pattern

/*WAP to get following

ABCDE
ABCD
ABC
AB
A
*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char a='A';
int i,j,k=0;
for(i=4;i>=0;i--)
{
  for(j=0;j<=i;j++)
    {
      printf("%c",a+j);
    }
  printf("\n");

}
getch();
}
-----------------
logic in mind
1) we have to display different characters in different rows and columns.
2)there are five rows and columns. The column is decreased in each display.
3)for this, we have used first loop for different rows.
4)second loop is for display. It fetches value from first loop and displays different character.
5)second loop is taken from value 0.because,  in each display, the character changes so. 
for more: look down.
--------------
program screenshot:-



program output:-


to display letters' pattern

/*to display following
A
AB
ABC
ABCD
ABCDE
*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char a='A';
int i,j,k=0;
for(i=1;i<=5;i++)
{
  for(j=0;j<i;j++)
    {
      printf("%c",a+j);
    }
  printf("\n");

}
getch();
}
-------------------
logic in mind:-
-------------
1) we have to display different characters in different rows and columns.
2)there are five rows and columns. The column is decreased in each display.
3)for this, we have used first loop for different rows.
4)second loop is for display. It fetches value from first loop and displays different character.
5)second loop is taken from value 0.because,  in each display, the character changes so.
for more: look down.
program screenshot:-


program output:-










to display letters' pattern

/*to display following
A
AB
ABC
ABCD
ABCDE
*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char a='A';
int i,j,k=0;
for(i=1;i<=5;i++)
{
  for(j=0;j<i;j++)
    {
      printf("%c",a+j);
    }
  printf("\n");
  //a++;
}
getch();
}
-------------------
logic in mind:-
-------------
1) we have to display different characters in different rows and columns.
2)there are five rows and columns. The column is decreased in each display.
3)for this, we have used first loop for different rows.
4)second loop is for display. It fetches value from first loop and displays different character.
5)second loop is taken from value 0.because,  in each display, the character changes so.
for more: look down.
program screenshot:-


program output:-










to display letters' pattern

/*to display following
A
AB
ABC
ABCD
ABCDE
*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char a='A';
int i,j,k=0;
for(i=1;i<=5;i++)
{
  for(j=0;j<i;j++)
    {
      printf("%c",a+j);
    }
  printf("\n");

}
getch();
}
-------------------
logic in mind:-
-------------
1) we have to display different characters in different rows and columns.
2)there are five rows and columns. The column is decreased in each display.
3)for this, we have used first loop for different rows.
4)second loop is for display. It fetches value from first loop and displays different character.
5)second loop is taken from value 0.because,  in each display, the character changes so.
for more: look down.
program screenshot:-


program output:-










Write a program to get following numeric pattern.

/*Write a program to get following numeric pattern.
0
01
012
0123                                                                                                                    
012
01
0
*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
for(i=0;i<=3;i++)
{
 for(j=0;j<=i;j++)
   {
      printf("%d",j);

   }
      printf("\n");
}
for(i=2;i>=0;i--)
{
 for(j=0;j<=i;j++)
   {
      printf("%d",j);

   }
      printf("\n");
}
getch();
}
-------------------------------------------------
logic in mind:-
1) we have to display given pattern.It has two parts
      first part is:upper part .i..e
        0
       01
       012
        0123   
  and second part is
     012
     01
     0
2)for first part, like shown below, we use loop to fetch value from outer loop and displaying from inner loop
3)for second part, we use once again loop with one less value. We fetch that and display from inner loop
just look down.

program's screenshot:

----------------------------
output screen:



program to display following star pattern.

 /*program to display following star pattern.
         * * * * * *
           * * * *
            * * *
             * *
              *
             *
            * *                                                                                                           
           * * *
         * * * *
       * * * * * 
*/
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int i,j,k,sp=1;
//printf("for upper part");
 for(i=1;i<=5;i++)
   {
for(k=sp;k<=i;k++)
  {
    printf(" ");

     }
    for(j=5;j>=i;j-- )
      {
printf(" *");
    }
    printf("\n");
}
 //printf("for lower part");

 sp=5;
 for(i=1;i<=5;i++)
   {
for(k=sp;k>=i;k=k-1)
  {   printf(" ");

     }
    for(j=1;j<=i;j++)
      {
      printf(" *");
    }
    printf("\n");
}
getch();

}
-------------------------------
logic in mind:-
---------------------------------
1)First loop is for number of rows.
2)like other programs, we display first upper part. 
       For this, we, first, display space (second loop)and then star(third loop.
3)For second part, we display first space(look diagram) using loop then we display star.
------------------------------------------------------------------------------------------------------------------------------
program's screenshot:-


programs output:-



program to display following star pattern.

/*program to display following star pattern.
              *
             *     *                                                                                                  
             *            *
             *                   *
             * * * * * * * * *                
             * *
             *     *
             *         *
             *             *
             *                  *
             *  * * * * * * * *
             *
             *
             *
*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,k,m,sp=7;
//printf("first upper part");
for(i=1;i<=5;i++)
 {

for(m=i;m<= i;m++)
{
printf("*");
}
 for(m=1;m<i;m++)
 {
 printf("  ");
 }
   for(m=i;m<=i;m++)
    {
      if(m==1)
      printf(" ");
      else
      printf("*");

    }

 printf("\n");
 }
 for(i=1;i<=10;i++)
 {
 printf("*");
 }
//printf("second lower part");
for(i=1;i<=5;i++)
 {

for(m=i;m<= i;m++)
{
printf("*");
}
 for(m=1;m<i;m++)
 {
 printf("  ");
 }
   for(m=i;m<=i;m++)
    {
      if(m==1)
      printf(" ");
      else
      printf("*");

    }

 printf("\n");
 }
 for(i=1;i<=10;i++)
 {
 printf("*");
 }
  for(i=1;i<=5;i++)
 {
 printf("*\n");
 }
 getch();
 }
-------------------------------
logics in mind:-
-------------------------------
1)it contains three parts:
        first part is upper right angled triangle
        second part is lower right angled triangle
        third part is tail
If we combine them then we get that.
2) To get upper part we have already done. follow the link
            https://practicingclanguage.blogspot.com/2016/09/program-to-display-following-star_21.html
3)To get lower part, follow the link
        https://practicingclanguage.blogspot.com/2016/09/program-to-display-following-star_21.html
4) to get left part, use loop few number of times. It's done
---------------------------------------------------------------------------------
Follow following shot for more.

program screenshot:-

output screen shot:-




program to display following star pattern/triangle

//program to display following star pattern/triangle
//program to display following star pattern
//              *
//           *     *                                                                                                    
//        *            *
//     *                   *
//  *                          *

//* * * * * * * * * * * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,k,m,sp=7;
for(i=1;i<=5;i++)
 {
     for(k=sp;k>=i;k--)
     {
       printf(" ");
     }
for(m=i;m<= i;m++)
{
printf("*");
}
 for(m=1;m<i;m++)
 {
 printf("  ");
 }
   for(m=i;m<=i;m++)
    {
      if(m==1)
      printf(" ");
      else
      printf("*");

    }
printf("\n");
}

 for(int i1=1;i1<=5;i1++)
 {

   printf(" * ");
 }

 getch();
 }
------------------------------
logic in mind
----------------------
1.)The given pattern has two parts.
          *
       *
  *
*
second 
             *
                *
                   *
                        *

and third is
 * * * * *  * * *
so for these three, we use three loops with spaces between them when we combine them.
1)since there are five asterisks we display using loop with decreasing spaces(see figure).First loop is used for number of rows used.Second loop is for space(decreasing)

2)third loop is displaying star.
3)the loop inside is for space and for right pattern display.then we display second part with increasing space between them. After that we display second part with next loop as shown below(picture).
4) In second part we use 'if' because we have to display first space rather asterisk so.

5)Now, left is last row.For this, we have used another loop as shown in picture given downside. 
---------------------------------------------------------------------------------------
more about this logic , you can understand from following screenshot.

-----------------------------------------------------------------------------------------------
program screenshot:-

output screenshot:-