star pattern

Display integrated pyramid star pattern in C using while loop

Display integrated pyramid star pattern in C using while loop

In this tutorial, we will discuss a concept of  Display integrated pyramid star pattern in C using while loop

In C  language, we can use for loop ,while loop and do-while loop to display different number (binary, decimal), alphabets or star patterns programs.

In this article, we are going to learn  how to Display integrated pyramid star pattern  using while loop in C  language

Display integrated pyramid star pattern in C

integrated Pyramid star pattern 1

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,rows;
    printf("Enter the number of rows: ");
    scanf("%d",&rows);  //get input from the user for rows
    i=1;
while(i<=rows){  //parent while loop
    j=i;
    while(j<=rows){  //print upper part of pattern
        printf("*");
        j++;
    }
    i++;
    printf("\n");
}

i=rows-1;
while(i>=1){   //print lower part of pattern
    j=i;
    while(j<=rows){
        printf("*");
        j++;
    }
    i--;
    printf("\n");
}
getch();
    return 0;
}

When the above code is executed, it produces the following results

pyramid star pattern 1

 

Integrated Pyramid star pattern 2

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,row;
    printf("Enter the number of rows :");
    scanf("%d",&row);  //get input from the user for rows
    i=1;
while(i<=row){
    j=1;
while(j<i){    
    printf(" ");
    j++;
}
j=i;
    while(j<=row){  
        printf("*");
        j++;
    }
    i++;
    printf("\n");
}

i=row-1;
while(i>=1){  //print lower part of pattern
    j=1;
while(j<i){
    printf(" ");
    j++;
}
j=i;
    while(j<=row){
        printf("*");
        j++;
    }
    i--;
    printf("\n");
}
 getch();
    return 0;

}

When the above code is executed, it produces the following results

pyramid star pattern 2

Integrated Pyramid star pattern 3

Program 3

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,row;
    printf("Enter the number of rows: ");
    scanf("%d",&row);  //get input from the user for rows
    i=1;
while(i<=row){
    j=1;
while(j<=i){   
    printf(" ");
    j++;
}
j=i;
    while(j<=row){
        printf("*");
        printf(" ");
        j++;
    }
    i++;
    printf("\n");
}

i=row-1;
while(i>=1){  //print lower part of pattern
    j=1;
while(j<=i){
    printf(" ");
    j++;
}
j=i;
    while(j<=row){
        printf("*");
        printf(" ");
        j++;
    }
    i--;
    printf("\n");
}
getch();
    return 0;
}

When the above code is executed, it produces the following results

pyramid star pattern 3

 

 

Integrated Pyramid star pattern 4

Program 4

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,row;
    printf("Enter the number of rows");
    scanf("%d",&row);  //get input from the user for rows
    i=1;
while(i<=row){
    j=1;
while(j<=row-i){   
    printf(" ");
    j++;
}
j=1;
    while(j<=i){
        printf("*");
        printf(" ");
        j++;
    }
    i++;
    printf("\n");
}

i=1;
while(i<=row-1){
    j=1;
while(j<=i){     //print lower part of pattern
    printf(" ");
    j++;
}
j=1;
    while(j<=row-i){
        printf("*");
        printf(" ");
        j++;
    }
    i++;
    printf("\n");
}
getch();
    return 0;
}

When the above code is executed, it produces the following results

pyramid star pattern 4

 

Integrated Pyramid star pattern 5

Program 5

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,k,rows;
    printf("Enter the number of rows: ");
    scanf("%d",&rows);   //get input from the user for rows
    i=1;
while(i<=rows){
  for(j=1; j<=i; j++){   //print upper part of pattern
  printf("*");

}

j=i*2;
while(j<rows*2){  
  printf(" ");
   j++;
}

k=i;
while( k>=1){  
  printf("*");
   k--;
}

  printf("\n");

   i++;

}
getch();
    return 0;
}

When the above code is executed, it produces the following results

pyramid star pattern 5

 

 

 

 

Integrated Pyramid star pattern 6

Program 6

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,k,rows;
    printf("Enter the number of rows: ");
    scanf("%d",&rows);  //get input from the user for rows

    i=rows;
while(i>=1){  //parent while loop
    j=rows;
  while(j>=1+rows-i){  //print upper part of pattern
  printf("*");
   j--;

}
     j=i*2;
    while(j<rows*2-1){
  printf(" ");
  j++;

    }

    k=1+rows-i;
    while( k<=rows){
    if(k!=1)
  printf("*");
 k++;

   }

  printf("\n");
  i--;

}
getch();
    return 0;
}

When the above code is executed, it produces the following results

pyramid star pattern 6

 

Similar post

Display integrated pyramid star pattern in C++ using while loop

Display integrated pyramid star pattern in Java using while loop

C code to print double pyramid star pattern

Java code to print double pyramid star pattern

C++ code to print double pyramid star pattern

 

Suggested for you

Data types in C language

Variable in C language

While loop in C language

Nested while loop in C language

 

 

C code to print Double pyramid star pattern
Display integrated pyramid star pattern in Java using while loop
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago