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)

  1. 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 NoOfStars by adding 2.
      • Modify NoOfSpaces by subtracting 1.

Task 2 (18 marks)

  1. 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