In this tutorial, we will discuss a concept of the C program to print combined Pyramid pattern
In the C programming language, we can use for loop ,while loop and do-while loop to display different number (binary, decimal), alphabets or star pattern programs.
In this article, we are going to learn how to Display combined Pyramid pattern using for loop in C language
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows\n"); scanf("%d",&rows); printf("\n"); for(i=1; i<=rows; i++){ //parent for loop for(j=i; j<=rows; j++){ printf(" "); //print space } for(j=1; j<=2*i-1; j++){ printf("*"); //print star } for(j=2*i; j<=2*rows-1; j++){ printf(" "); //print space } for(j=1; j<=2*i-1; j++){ printf("*"); //print star } printf("\n"); //move to next line } getch(); return 0; }
When the above code is executed, it produces the following results
The C program allows the user to enter the number of rows then it displays two combined straight pyramid star pattern according to the number of rows.
Program 2
#include <stdio.h> #include <stdlib.h> int main() {int i,j,rows; printf("Enter the number of rows\n"); scanf("%d",&rows); printf("\n"); for(i=1; i<=rows; i++){ for(j=1; j<i; j++){ printf(" "); } for(j=1; j<2*(rows-i+1); j++){ printf("*"); } for(j=2; j<2*i; j++){ printf(" "); } for(j=1; j<2*(rows-i+1); j++){ printf("*"); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results
The C program allows the user to enter the number of rows then it displays two combined upside-down pyramid star pattern according to the number of rows.
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows\n"); scanf("%d",&rows); printf("\n"); for(i=1; i<=rows; i++){ for(j=i; j<=rows; j++){ printf(" "); } for(j=1; j<=2*i-1; j++){ printf("%d",j); } for(j=2*i; j<=2*rows-1; j++){ printf(" "); } for(j=1; j<=2*i-1; j++){ printf("%d",j); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results
The C program allows the user to enter the number of rows then it displays two combined straight pyramid number pattern according to the number of rows.
Program 2
#include <stdio.h> #include <stdlib.h> int main() {int i,j,rows; printf("Enter the number of rows\n"); scanf("%d",&rows); printf("\n"); for(i=1; i<=rows; i++){ for(j=1; j<i; j++){ printf(" "); } for(j=1; j<2*(rows-i+1); j++){ printf("%d",j); } for(j=2; j<2*i; j++){ printf(" "); } for(j=1; j<2*(rows-i+1); j++){ printf("%d",j); } printf("\n"); } getch(); return 0; }
When the above code is executed, it produces the following results
The C program allows the user to enter the number of rows then it displays two combined upside-down pyramid number pattern according to the number of rows.
Similar post
Java program to the combined Pyramid pattern
C++ program to the combined Pyramid pattern
Suggested for you
Input and output function in C language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…