CS50x Week 1: C

I have learnt about libraries, compilers, switch statements, and typecasting. When we are programming, we are giving instructions to the computer to carry out tasks. However, the programming language like C is considered a high level language. High level language is easy to read (resembles english), while low level language is cryptic. Computers only read in binary (0s and 1s), so we have to change the high level language code that we wrote, to a low level machine code that the computer can understand. The step is carried out by a compiler.

Compiler carries out 4 functions, namely, preprocessing, compiling, assembling, and linking. Preprocessing reads the top part of your C code, that is the “#include ” line. It takes the codes prewritten in the something.h library to your code. Next, compiling C code turns the C code to assembly language. Then, the assembly language is assmbled into object codes. Linker links the object codes into machine code (0s and 1s) that the computer can read.

Besides learning about theory, CS50x also taught me how to make some useful simple programs. You have to include the cs50.h header for the programs to work. cs50.h is available when you take the class.

Program 1 (Hello.c)

Print Hello, world.

Image and video hosting by TinyPic

Program 2 (mario.c)

Print the mario stair.

Image and video hosting by TinyPic

Program 3 (greedy.c)

Convert your money to quarters (25¢), dimes (10¢), nickels (5¢), and pennies (1¢). Rule: Use the least number of coins.

Image and video hosting by TinyPic

Program 4 (credit.c)

Check if number is valid credit card number, and list out the type of credit card.

I use the numbers from following link to test my program.


This program can only work for American Express, MasterCard, and Visa.

Image and video hosting by TinyPic

Program 5 (mario2.c)

Advance version of mario stair program.

Image and video hosting by TinyPic

My codes: https://github.com/shaunlgs/CS50x
Other posts in the series: Harvard CS50x 2014

One thought on “CS50x Week 1: C”

  1. did you notice the translational errors in your posted code, where ‘>’ & ‘<' are transposed into "<" and ">"

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.