How To Draw A Hollow Triangle In C++ With Visual Studio
In this article, I will show you, How to write a C program to print hollow pyramid star design or hollow equilateral triangle star pattern series of northward rows using for loop. How to print hollow pyramid star design in C programming. Here, one matter is of import to know that the rows of the pyramid.
Logic to print hollow pyramid star design ( equilateral triangle star blueprint)
- Enter the row value for the equilateral triangle.
- Hither I have used three loops i is the outer loop to alter the line and two inner loops to print star and space.
- The outer loop iterate row times and print a newline afterwards completing the inner loop.
- First inner loop impress the infinite 10 to (N-one)(where N is the row number and ten is the current row number).
- The 2d inner loop print the star at xth or terminal column or for terminal row. Information technology iterates from one to (two*x)-1).
Run into the, C program to print hollow pyramid star pattern:
#include <stdio.h> int main() { int x = 0,y = 0; unsigned int rows = 0; printf("Enter the number of rows = "); scanf("%u",&rows); for(10=ane; x<=rows; ++x) { // Print spaces for(y=10; y<=rows; ++y) { printf(" "); } for(y =ane; y<=((2*ten)-ane); ++y) { //Impress star only first and last row col if(x==rows || y==one || y==((two*x)-1)) { printf("*"); } else { printf(" "); } } // Print new line printf("\n"); } return 0; }
Output:
Code Analysis:
It asks the user to enter the row for the hollow pyramid (equilateral triangle).
printf("Enter the number of rows = "); scanf("%u",&rows)
commencement, inner loop print space x to (Northward-i) times.
// Print spaces for(y=x; y<=rows; ++y) { printf(" "); }
The second inner loop print the star at x-th or final column or for the concluding row otherwise it prints space.
Source: https://aticleworld.com/c-program-to-print-hollow-pyramid-equilateral-triangle-star-pattern/
Posted by: yeltonthationothe.blogspot.com
0 Response to "How To Draw A Hollow Triangle In C++ With Visual Studio"
Post a Comment