In this tutorial, we will discuss a concept of Hollow Triangle Pattern using nested while loop in C
In this program, we are going to learn about how to display Hollow Tringle star pattern using nested while loop in C programming language
Here, we display some Hollow triangle Pattern program with coding using nested while loop and also program get input from the user using scanf() function in C programming language
The user can provide numbers as they wish and get the Hollow Triangle pattern according to their input.
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows\n"); scanf("%d",&rows); i=1; while(i<=rows){//outer while loop j=1; while(j<=i){//inner for loop printf(" ");//print initial space if(j==1 || j==i ||i==rows ) printf("*");//print star else printf(" "); //print inside space j++;; } i++; printf("\n");//Move to the next line for print } return 0; }
When the above code is executed, it produces the following results
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows\n"); scanf("%d",&rows); i=1; while(i<=rows){..outer for loop j=i; while(j<rows){ printf(" ");//print space j++; } j=1; while(j<=i){ if(j==i || j==1 ||i==rows ) printf("*");//print star else printf(" ");//print space j++;; } i++; printf("\n");//Move to the next line for print } getch(); return 0; }
When the above code is executed, it produces the following results
Program 3
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows\n"); scanf("%d",&rows); i=1; while(i<=rows){//outer for loop j=1; while(j<=rows){//inner for loop if(j==i || j==rows ||i==1 ) printf("*");//print star else printf(" ");//print space j++;; } i++; printf("\n");//Move to the next line for print } getch(); return 0; }
When the above code is executed, it produces the following results
Program 4
#include <stdio.h> #include <stdlib.h> int main() { int i,j,rows; printf("Enter the number of rows\n"); scanf("%d",&rows); i=1; while(i<=rows){//outer for loop j=i; while(j<=rows){//inner for loop if( i==1|| j==i || j==rows) printf("*");//print star else printf(" ");//print space j++;; } i++; printf("\n");//Move to the next line for print } getch(); return 0; }
When the above code is executed, it produces the following results
Suggested for you
Nested while loop in C language
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,…