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 toDisplay combined Pyramid pattern using for loop in C language
program to the combined Pyramid star pattern
Combined Pyramid star pattern 1
Program 1
#include
#include
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
jointed Pyramid pattern 1
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.
Combined Pyramid star pattern 2
Program 2
#include
#include
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
When the above code is executed, it produces the following results
Jointed Pyramid pattern 2
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 to the combined Pyramid number pattern
Combined Pyramid number pattern 1
Program 1
#include
#include
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
Jointed Pyramid pattern 3
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.
Combined Pyramid number pattern 2
Program 2
#include
#include
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
When the above code is executed, it produces the following results
Jointed Pyramid pattern 4
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.