C program to print square number pattern 1

Ex: Write a C program to print given square number pattern. How to write a C program to print given square number pattern. C program to print given square number pattern.


Input from user:

Enter the number: 5


Expected output:

11111

11111

11111

11111

11111




  Step by step logic of the given program:


To print this pattern, first you need understand square star pattern:


1. Accept input number from user declare variable say no.


2. Run outer for loop  from 1 to no to print number of rows.


3. Run inner for loop from 1 to no to print number of columns.


4. Inside the inner loop print 1.


5. For next row print new line \n.




Program:


#include<stdio.h>

void main()

{

int no;

int i,j;

printf("Enter the number:");

scanf("%d",&no);

/*Loop to print rows */

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

{

          /*Loop to print columns */

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

{

/*you can add any number here to print their pattern*/

                      printf("1");

}

/*for new line*/

printf("\n");

}

}



Above program shows the following output:


C program to print square number pattern 1




C Program to Print Heart Shape Star Pattern

Ex: Write a C program to print heart shape star pattern. How to write a C program to print heart shape star pattern. C program  to print heart shape star pattern.


Input from user:

Enter the number: 5

Expected output:
    **     **
  ****   ****
   *********
     *******
       *****
         ***
           *




  Step by step logic of the given program:


1. Accept input number from user.

2. To print upper part of the pattern:
  • Print left peak:
     **
   ****

  • Print right peak:
     **
   ****

3. After that print lower part means inverted triangle:
*********
  *******
    *****
      ***
        *

4. Then you will get heart shape pattern:
    **     **
  ****  ****
  *********
    *******
      *****
        ***
          *




Program:

#include<stdio.h>
void main()
{
int no,i,j,k,z;
printf("Enter the number:\n");
scanf("%d",&no);
/*To print upper part*/
z=no*2;
for(i=no/2;i<=no;i=i+2)
{
/*To print left peak */
for(j=1;j<no-i;j=j+2)
{    
                    printf(" ");
}
for(k=1;k<=i;k++)
{
printf("*");
}
/*To print right peak*/
for(j=1;j<=no-i;j++)
{
    printf(" ");
}
for(k=1;k<=i;k++)
{
printf("*");
}
printf("\n");
}
/*To print lower part means inverted triangle*/
for(i=1;i<=no;i++)
{
for(j=1;j<i;j++)
{
printf(" ");
}
for(k=1;k<z;k++)
{
printf("*");
}
z-=2;
printf("\n");
}
}


Above program shows the following output:

C program to print heart shape star pattern, heart pattern in C



C program to print inverted half right side of pyramid star pattern

 Ex: Write a C program to print inverted half right side of pyramid star pattern. How to write a C program to print inverted half right side of pyramid star pattern. C program to print inverted half right side of pyramid star pattern.


Input from user:

Enter the number:

5


Expected output:

*****

****

***

**

*



  Step by step logic of the given program:


1. Accept input number from user declare variable say no.


2. Run outer for loop from 1 to no which shows rows in pattern:

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


3. Run inner for loop from i to no which shows columns in pattern:

for(j=i;j<=no;j++)


4. Inside the inner loop print star:

printf("*");


5. For next row print \n.





Program:


#include<stdio.h>

void main()

{

int i,j,no;

printf("Enter the number:\n");

scanf("%d",&no);

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

{

for(j=i;j<=no;j++)

{

printf("*");

}

printf("\n");

}

}



Above program shows the following output:


C program to print inverted half right side of pyramid star pattern



C program to print inverted half left side of pyramid star pattern

 Ex: Write a C program to print inverted half left side of the pyramid star pattern. How to write a C program to print inverted half left side of the pyramid star pattern. C program to print inverted half left side of the pyramid star pattern.



Input from user:

Enter the number:

5


Expected output:

*****

  ****

    ***

      **

        *



  Step by step logic of the given program:


1. Accept input number from user declare variable say no.


2. Run outer for loop from 1 to no which shows number of rows:

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


3. Run inner for loop from 1 to i-1 to print spaces: 

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

{

printf(" ");

}


4. Run another one inner for loop from i to no to print star:

for(k=i;k<=no;k++)

{

printf("*");

}


5. For next row print \n.




Program:


#include<stdio.h>

void main()

{

int i,j,k,no;

printf("Enter the number:\n");

scanf("%d",&no);

/*Run loops*/

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

{

                /* Print spaces from second row, in incremented manner*/

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

{

printf(" ");

}

                /* Print stars in decremented manner*/

for(k=i;k<=no;k++)

{

printf("*");

}

                /* For next row*/

printf("\n");

}

}



Above program shows the following output:


C program to print inverted half left side of pyramid star pattern

C program to print half left side of the pyramid star pattern

 Ex: Write a C program to print half left side of the pyramid star pattern. How to write a C program to print half left side of the pyramid star pattern. C program to print half left side of the pyramid star pattern.


Input from user:

Enter the number:

5


Expected output:

        *

      **

    ***

  ****

*****



  Step by step logic of the given program:


1. Accept input number from user declare variable say no.


2. Run outer loop from 1 to no which shows the number of rows in pattern:

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


3. Run first inner loop from i to no-1 to print spaces:

for(j=i;j<no;j++)


4. Run second inner loop from 1 to i to print star:

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


5. For next row print \n.




Program:


#include<stdio.h>

void main()

{

int no,i,j,k;

printf("Enter the number:\n");

scanf("%d",&no);

/*Run loops*/

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

{

for(j=i;j<no;j++)

{

    printf(" ");

}

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

{

    printf("*");

}

/*For new row*/

        printf("\n");

}


}


Above program shows the following output:


C program to print half left side of the pyramid star pattern



C program to print half right side of pyramid star pattern

 Ex: Write a C program to print half right side of  the pyramid star pattern. How to write a C program to print half right side of the pyramid star pattern. C program to print half right side of the pyramid star pattern.



Input from user:

Enter the number:

5


Expected output:

*

* *

* * *

* * * *

* * * * *



  Step by step logic of the given program:


1. Accept input number from user declare variable say no.


2. Run outer for loop from 1 to no which shows rows in pattern:

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


3. Run inner for loop from 1 to  i which shows columns in pattern:

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


4. Inside the inner loop print star:

printf("*");


5. For next row print \n.





Program:


#include<stdio.h>

void main()

{

int no,i,j;

printf("Enter the number:\n");

scanf("%d",&no);

/*Run loops*/

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

{

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

{

/* print star*/

printf("*");

}

/*For new row*/

printf("\n");

}

}



Above program shows the following output:


C program to print half right side of pyramid star pattern





C program to print hollow square star pattern

 Ex: Write a C program to print hollow square star pattern. How to write a C program to print hollow square star pattern. C program to print hollow square star pattern.


Input from user:

Enter the number:

7


Expected output:

C program to print hollow square star pattern




  Step by step logic of the given program:

1. Accept input number from user declare variable say no.


2. Run outer loop from 1 to no which will shows rows of pattern:

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


3. Run inner loop from 1 to no which will shows columns of pattern:

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


4. Using if statement give conditions to print stars:

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


5. Otherwise print spaces (to print it like hollow).


6. For next row use new line (\n).




Program:


#include<stdio.h>

void main()

{

int no,i,j;

printf("Enter the number:\n");

scanf("%d",&no);

/*Run loops from 1 to no*/

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

{

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

{

/*Give conditions to print stars*/

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

{

printf("*");

}

else

{

/*Otherwise print spaces*/

                             printf(" ");

}

}

/*For new row*/

        printf("\n");

}

}



Above program shows the following output:


C program to print hollow square star pattern


C program to print Rhombus star pattern

Ex: Write a C program to print Rhombus star pattern. how to print Rhombus star pattern using for loop. C Program to print Rhombus star Pattern.
In below code we  print Rhombus star pattern.



Input from user:

Enter the number: 5

Expected output:

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




  Step by step logic to print Rhombus star pattern.

1. Accept input (number) from user declare variable say no.


2. Run a loop(outer loop), to iterate through rows and increment i by 1:

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


3. After that to print spaces run another loop(inner loop):

for(j=1;j<=no-i; j++)
{
printf(" ");
}


4. To print stars run another loop(inner loop) from 1 to no. Print star inside this loop:

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

 {

printf("*");

 }


5. After printing all columns of a row, print new line (\n), for move it to next line.





Program:

/***C program to print Rhombus star pattern***/

#include<stdio.h>
void main()
{
int i,j,k,no;

printf("Enter the number:\n");/*take input number from user which denotes number of rows*/
scanf("%d",&no);

for(i=1;i<=no;i++)
{
for(j=1;j<=no-i; j++)
{
printf(" ");
}
for(k=1;k<=no;k++)
    {
      printf("*");
    }
    printf("\n");//for new line
}
}

Above program shows the following output:

C program to print Rhombus star pattern

C program to print mirrored rhombus star pattern

Ex: Write a C program to print mirrored rhombus star pattern. How to write a C program to print mirrored rhombus star pattern. C program to print mirrored rhombus star pattern.


Input from user:

Enter the number:

5


Expected output:

*****

 *****

  *****

   *****

    *****



  Step by step logic of the given program:


1. Accept input (number) from user declare variable say no.


2. Run a loop(outer loop), to iterate through rows and increment i by 1:

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


3. After that to print spaces run another loop(inner loop):

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

{

printf(" ");

}


4. To print stars run another loop(inner loop) from 1 to no. Print star inside this loop:

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

 {

printf("*");

 }


5. After printing all columns of a row, print new line (\n), for move it to next line.





Program:


#include<stdio.h>

void main()

{


 int i,j,k,no;

   /*Take input number from user which denotes number of rows and columns in pattern*/

   printf("Enter the number:\n");

   scanf("%d",&no);

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

   {

     /*Print spaces*/

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

{

printf(" ");

}

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

{

printf("*");

}

     printf("\n");//for new line

 }

}


Above program shows the following output:


C program to print mirrored rhombus star pattern