We read your photo as:
Write a C program to print a pyramid of stars. Detail the logic for calculating spaces and stars for each line and provide the Initialise procedure.
Computer Science
ScanSolve AI Answer
Here are the answers to your questions:
Task 1 (9 marks)
-
i) The initial value for
MaxNoOfStars(the number of stars at the base of the pyramid) is 9.ii) For the first line:
- The number of leading spaces (
NoOfSpaces) is 4. - The number of stars (
NoOfStars) is 1.
iii) For the second line:
- The number of leading spaces (
NoOfSpaces) is 3. - The number of stars (
NoOfStars) is 3.
iv)
- Between successive lines (moving downwards from the top of the pyramid), the number of stars increases by 2.
- Similarly, the number of leading spaces decreases by 1.
- Therefore, before printing the next line in the Pyramid, you should:
- Modify
NoOfStarsby adding 2. - Modify
NoOfSpacesby subtracting 1.
- Modify
- The number of leading spaces (
Task 2 (18 marks)
-
i) The procedure
Initialise(Max, Spaces, Stars)in C programming language:void Initialise(int Max, int *Spaces, int *Stars) { // MaxNoOfStars is represented by the 'Max' parameter itself. // Initialise NoOfStars for the first line *Stars = 1; // Initialise NoOfSpaces for the first line *Spaces = (Max - 1) / 2; }
Was this helpful?
Still stuck on this one?
Ask a follow-up, and the answer starts from this question.
Got a different question?Ask your own question
More Computer Science Questions
QWrite a C program to print an X pattern of asterisks based on the number of rows.QWrite a Python program to print a pyramid of base 7. Test it, screenshot the output as task3, and…QWrite a Python program to print a pyramid pattern for a given odd base. Test the program with a base…QWrite a C program to dynamically allocate memory for an array of strings, allowing the user to input…QHow to write a programing code
Browse by topic:Programming