Write a C Program to Print Hollow Right Triangle Star Pattern using for loop. This example uses for loops and the if-else statements to print the hollow Right Triangle star pattern.
#include<stdio.h> int main() { int i, j, rows; printf("Enter Hollow Right Triangle Rows = "); scanf("%d", &rows); printf("Hollow Right Triangle Star Pattern\n"); for(i = 1; i <= rows; i++) { if(i == 1 || i == rows) { for(j = 1; j <= i; j++) { printf("*"); } } else { for(j = 1; j <= i; j++) { if(j == 1 || j == i) { printf("*"); } else { printf(" "); } } } printf("\n"); } return 0; }
In this Program, we used the while loop to print a hollow Right angled triangle Pattern. It allows entering the hollow Right Triangle pattern symbol.
#include<stdio.h> int main() { int i, j, rows; char ch; printf("Symbol to Print Hollow Right Triangle = "); scanf("%c", & ch); printf("Enter Hollow Right Triangle Rows = "); scanf("%d", &rows); printf("Hollow Right Triangle Star Pattern\n"); i = 1; while(i <= rows) { if(i == 1 || i == rows) { j = 1; while(j <= i) { printf("%c", ch); j++; } } else { j = 1; while(j <= i) { if(j == 1 || j == i) { printf("%c", ch); } else { printf(" "); } j++; } } printf("\n"); i++; } return 0; }
Symbol to Print Hollow Right Triangle = #
Enter Hollow Right Triangle Rows = 10
Hollow Right Triangle Star Pattern
#
##
# #
# #
# #
# #
# #
# #
# #
##########