• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #438
    admin
    Keymaster
      
      
      #include <stdio.h> 
      #include <cs50.h>
      
      int main(void)
      {
          int h;
          do
          {
              h = get_int("height");
          }
          while (h < 1 || h > 8);
          for (int y = 0; y < h; y++)
          {
              for (int i = h - y - 1; i > 0; i--)
              {
                  printf(" ");
              }
              for (int j = 0; j < y + 1; j++)
              {
                  printf("#");
              }
              printf("  ");
      
              for (int j = 0; j < y + 1; j++)
              {
                  printf("#");
              }
              printf("\n");
          }
      
      }

      Mario-more project

      Mario-more project is almost similar to Mario-less. There is perhaps no reason why one cannot handle Mario-more project if completed Mario-less.

      Here are the key takeaways:

      1. Forming nested loop (for loop preferably) that utilizes the height (h) of the pyramid and no. of rows (y) to relate characters (blank space, #) will lead to the solution.
      2. First focus on blank space in first column. For better visibility while working, you can use dot or any other character instead of blank space. With nested for loop and new line, check if the next row displays what is intended.
      3. Once you find a formula with for loop that correctly displays blank spaces, next focus on # (bricks).
      4. Putting two blank spaces on each row is constant and do not need for loop like blank spaces and # earlier.
      5. Next, paste the for loop that you formed for #. You are done as after #, there will be automatically blank spaces.

      The Mario project should help create any shape that is a result of rows and columns. Once a pattern discovered, creating a suitable loop helps achieve the goal. If no pattern is there which can be expressed in terms of relationship between columns and rows, then of course, it negates the use of loop, thereby making the task more manual. In the Mario problem, the pyramid can be expressed in terms of a pattern which is a function of two characters: blank space and #. For each subsequent row, there is a fixed increase/decrease in blank space/#. The important thing here is not a particular shape such as square or pyramid but a pattern that can be expressed in terms of a functional relationship between rows and columns.

      Mario project cs50

       

       [learn_press_profile]

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Scroll to Top