In this tutorial, we will discuss How to create hollow triangle pattern in C programming language
We can print many types of hollow triangle pattern in C programming language
We describe four hollow patterns in this post
Hollow triangle star patterns in C language
Pattern 1
Hollow triangle Program 1
#include
#include
int main()
{
int i,j,rows;//variable declaration
//Input row value from user
printf("Enter of rows you want\n");
scanf("%d",&rows);
for(i=1; i<=rows; i++){//parent for loop
for(j=i; j<=rows; j++){//print columns
if(i==1 || j==i || j==rows){
printf("*");
}
else{
printf(" ");
}
}
printf("\n");//move to next line
}
getch();
return 0;
}
When the above code is executed, it produces the following results:
Hollow triangle pattern 1
Program 2
Hollow triangle pattern 2
#include
#include
int main()
{
int i,j,rows;//variable declaration
//Input row value from user
printf("Enter of rows you want\n");
scanf("%d",&rows);
for(i=1; i<=rows; i++){//parent for loop, for row of hollow triangle
for(j=1; j<=i; j++){//print columns
if(j==1 || j==i || i==rows){
printf("*");
}
else{
printf(" ");
}
}
printf("\n");//move to next line
}
getch();
return 0;
}
When the above code is executed, it produces the following results:
Hollow triangle pattern 2
Program 3
Hollow triangle pattern 3
#include
#include
int main()
{
int i,j,rows;//variable declaration
printf("Enter the number of rows you want: ");
scanf("%d",&rows);//get input from user for rows
for(i=1; i<=rows; i++){
for(j=1; j
Hollow triangle pattern 3
Program 4
Hollow triangle pattern 4
#include
#include
int main()
{
int i,j,rows;
printf("Enter the number of rows you want: ");
scanf("%d",&rows);//get input from user for rows
for(i=1; i<=rows; i++){
for(j=i; j
When the above code is executed, it produces the following results: