C program to calculate area and perimeter of square and rectangle. To calculate area and perimeter of a square and rectangle in C Programming, you have to ask to the user to enter length and breadth of rectangle and side length of square and make two variable one for area and one for perimeter for each to perform mathematical calculation and display the result. In this C language tutorial we will look at a much-requested subject, printing a star pyramid and a string triangle using for loops. We know that this question is often asked as part of homework (lab) assignments, but we got so much requests that we couldn’t ignore it. BUT we are urging you to at least try to make the homework questions yourself!
In this program, you will learn in-depth about C++ program to print star pyramid patterns of various types using nested loops.
|Example 1: Full star pyramid pattern|
|Example 2: Inverted full star pyramid pattern|
|Example 3: Half star pyramid pattern|
|Example 4: Inverted half star pyramid pattern|
|Example 5: Hollow star pyramid pattern|
|Example 6: Inverted hollow star pyramid pattern|
To print star pyramid patterns in C++ programming, we have used two nested for loops.
Use a series of nested if / else statements to determine if the triangle having side-lengths as set by the user is an EQUILATERAL, ISOSCELES, or SCALENE triangle. Note: look to the Wikipedia page on ‘triangle’ for definitions of these three types of triangles. Print the resulting triangle type to the console.
The outer for loop is responsible for the number of rows in star (*) pyramid triangle or patterns whereas inner for loop will print the required number of stars * in each row.
Let’s take a look at various star pattern printing programs in C++.
In this Example we will learn how to Print Diamond of Stars in C++ /daisydisk-linuc.html.
cout<<'nnEnter number of rows: ';