Cs50 Problem set 1 Solutions 2021: My step by step explanations

Oh yes, I’m so ecstatic, I’ve been able to Cs50 complete Problem set 1, though Mario, Cash, and Credit seem undoable for me at first, after working sleeplessly and thorough research I’ve been able to attempt all. Hello pset is just a copy-paste of what Prof David J.Malan taught us in the video.

here comes my solution, worry not I’ve been able to compile all solutions, if you find anyone daunting or you don’t understand kindly use the comment box, will get back to you.

So let’s dive in.

What To do in Pset1?

We are to go to ide.cs50.io and click “Sign in with GitHub” to access your CS50 IDE.

  • Submit Hello
  • Then Submit one of Mario, either feeling less or more comfortable.

Submit one of:

  • Cash if feeling less comfortable
  • Credit if feeling more comfortable

Cs50 Problem set 1 Hello Solution

Hello seems to be the easiest of all in this Pset, it only requires you to print your name by writing a program that asks your name and prints out (Hello your name).


  • Prompt User for their name
  • then say Hello User
my hello.c solution

Hello Code explanation

  • I declare a string variable “name” with get_string and ask “What is your name:”
  • Then print the user’s name with printf(); and also input “hello %s” to make it print the user’s name.

Cs50 Mario less Comfortable Solution

This program was meant to mimics Super Mario steps used in the game, we are to use ‘#’ to represent the above picture like this



  • Prompt user for height
  • If the height is less than 1 or greater than 8 (or not an integer at all), go back one step
  • Iterate from number through height:
  • On iteration, print hashes and then a newline

Mario less code explanation here

  • I declare user Mario height with int “height”
  • I use do while loop to make sure the user cooperates and doesn’t input height larger than 8 or less than 1.
  • Then use for loop to iterate row over the height so that it can print 8 rows.
  • Then use another for loop to iterate over row and height for it to print the space required for program to left align the Mario steps.
  • Hash for loop iterate over row for it to print the “#” like the order of the step

Mario More Comfortable Solutions

This program was meant to print two way super Mario steps with hash “#”.


  • The same thing for Mario less, the only thing we are adding is Right align Hash

Mario more comfortable code explanation

  • we will start from where we stop the solution at Mario less Comfortable solution.
  • then print two space printf(” ” );
  • after then iterate another for loop (right_hash) with row to print right align hash.

Cs50 Problem Set 1 Cash Solution

This Problem set was meant to help sellers make a change for buyer’s easily, It’s design to help the cashier collate the lowest possible number of coins to help make a change for Customers.


  • Prompt user for an amount of Change
  • if the change is less than 0, reprompt the user until cooperate.
  • Due to floating impression, round the cent to the nearest penny
  • Then use the largest coins possible, keeping track of coins used.
  • Print the number of coins.

Cash code explanation

  • I declare a float variable with the name “Change”.
  • Then I use a do-while loop, to make sure the user did not input digit less than 0;
  • I use while loop and Subtraction to divide the Change by the Coins (25¢, 10¢, 5¢, 1¢),
  • thus using count variable to count the number of times coins is used to divide the money.
  • then I print the number of coins with the count.

Cs50 pset1 Credit Solution

This Problem set took me hours before completing it. since it wasn’t important, I was so close to quitting at first.

This pset was set to write a program that Checks if a Credit card is Valid or not, for example, to check if a MasterCard is Valid or not.


  • Prompt User for Card Number
  • Calculate the Checksum if the card is Valid
  • Check for Card length and Starting digits

Credit code explain here
Due to the long code, pls check the above code comment for a better explanation, than


Problem set 1 took me hours before completing it, especially Credit.c, I had to browse the whole internet to check for guides and how to implement.

I also learned that this Pset’s will be like foundaton for the coming week’s pset, so make sure you understand all line of codes to avoid problem in the future.

Thanks for reading…. I hope you find the post helpful.

Have any questions? pls feel free to ask using the comments box below. Thanks🤗

1 comment

  1. Hello, I have a question about the “cash” task (change in coins). When I compile it , the system gives the error C99 implicit declaration of function printf is invalid. I googled it, and all the answers say that it’s because the headers are not icluded. But I included correctly all the headers (cs50.h , stdio.h, and math.h). Do you have any idea of why this error happens?

Leave a Reply