Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Program pyramid.cpp in c++ a. Prompt and read the value of n from the user. This value must be positive and an odd number. Note
Program pyramid.cpp in c++
a. Prompt and read the value of n from the user. This value must be positive and an odd number. Note that zero is not positive. Use a while loop to repeatedly prompt and reread this value from the user if a value entered is invalid.
b. Use for loop(s) to print the inverted pyramid.
c. Debug your program by running it on different values of n, e.g. 1, 3, 11, 51, etc
Write a program pyramid.cpp that reads a positive odd whole number n and prints a pyramid where the first row contains all numbers from n down to 1 (i.e., descending order), the second row displays all numbers from n -1 down to 2, the third row displays all numbers from n -2 down to 3, etc. The last row will contain only a single value, i.e. the middle value in the range, i.e. n down to 1. Each successive row contains two fewer values than the previous row, i.e. the two values at the ends of the previous row are missing. For example, if n is 9, then the program will output: 987654321 8765432 76543 654 If n is 13, then the program will output: 3210987654321 21098765432 109876543 0987654 98765 876 The i'th row contains (2i 2) values. Each column displays the same number. If a row has more than 10 digits, the digit after 0 should start again from 9Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started