In this tutorial, we will discuss a simple concept of te C code to print Double pyramid star pattern
In this post, we will learn how to create double (integrated) pyramid star pattern in C language.
We can use for loop, while loop or do while loop to display different integrated star patterns.
Here, we will use for loop to print different Double(integrated) pyramid star patterns
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j; printf("Enter the number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; i++){ //print upper part for(j=i; j<=rows; j++){ printf("*");//print star } printf("\n"); } for(i=rows-1; i>=1; i--){ //print lower part for(j=i; j<=rows; j++){ printf("*");//print star } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following result
Enter the number of rows: 6 ****** ***** **** *** ** * ** *** **** ***** ******
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j,k; printf("Enter the number of rows\n"); scanf("%d",&rows); for(i=1; i<=rows; i++){ //print upper part for(j=1; j<=i; j++){ printf(" "); } for(k=i; k<=rows; k++){ printf("*");//print star to upper part printf(" "); } printf("\n");//move to next line } for(i=rows-1; i>=1; i--){ //print lower part for(j=1; j<=i; j++){ printf(" "); } for(k=i; k<=rows; k++){ printf("*");//print star to lower part printf(" "); } printf("\n");//move to next line } getch(); return 0; }
When the above code is executed, it produces the following result
Enter the number of rows: 6 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Program 3
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j; printf("Enter the number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; i++){ //print upper part for(j=1; j<i; j++){ printf(" ");//print space } for(j=i; j<=rows; j++){ printf("*");//print star to upper part } printf("\n");//move to next line } for(i=rows-1; i>=1; i--){ for(j=1; j<i; j++){ printf(" ");//print space } for(j=i; j<=rows; j++){ //print lower part printf("*");//print star to lower part } printf("\n"); } return 0; }
When the above code is executed, it produces the following result
Enter the number ofrows: 6 ****** ***** **** *** ** * ** *** **** ***** ******
Program 4
#include <stdio.h> #include <stdlib.h> int main() { int rows,i,j,k; printf("Enter the number of rows: "); scanf("%d",&rows); for(i=1; i<=rows; i++){ //print upper part for(j=1; j<=rows-i; j++){ printf(" "); } for(k=1; k<=i; k++){ printf("*");//print star to upper part printf(" "); } printf("\n"); } for(i=1; i<=rows-1; i++){ //print lower part for(j=1; j<=i; j++){ printf(" "); } for(k=1; k<=rows-i; k++){ printf("*");//print star to lower part printf(" "); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following result
Enter the number of rows: 6 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Similar post
C++ code to Double pyramid star pattern
Java code to Double pyramid star pattern
Suggested for you
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…