• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
August 24, 2022 |1.3K Views

C Program For Printing 180 Degree Rotation of Simple Pyramid

Description
Discussion

In this video, we will write a C program for printing 180-degree rotation of a simple pyramid

To print a simple pyramid, you should rotate the object 90 degrees along the y axis. This way, the pyramid will look like a regular triangle.

Example:
Input: n= 3
Output = 
*
**
***

Here we see 3 different approaches for printing a 180-degree rotation of a pyramid.

1. Using Nested for loop: First for loop is used to identify the number of rows and the second for loop is used to identify the number of columns. Here the values will be changed according to the first for loop. If j is greater than I then it will print the output otherwise print the space.

2. Using Nested While Loop: The while loops check the condition until the condition is false. If the condition is true then enters into a loop and executes the statements.

3. Using Recursion and a for loop: Here we call a recursion function with three parameters n, space, and an asterisk. After printing a simple pyramid with the help of for loop.

The time complexity will be high and space complexity will be low in the first 2 approaches, But the opposite (time complexity low and space complexity high) will happen in Approach-3.

C Program For Printing 180 Degree Rotation of Simple Half Left Pyramid
https://www.geeksforgeeks.org/c-program-for-printing-180-degree-rotation-of-simple-half-left-pyramid/