hw05 - Intro to C Loops

Make sure that you follow all the coding standards
From Linux on the GL machine:
  • Write a C program (see below) and save it in a file called numConvert.c in your ./CMSC104/hw5 directory
  • Compile the program:     
    gcc -lm -o numConvert numConvert.c
  • Run the program to make sure it works:     
    ./numConvert
  • Use the SUBMIT utility turn in the homework.     
    submit cs104_grasso hw05 numConvert.c numConvert

Create a program that does the following:
  • Prompt the user to enter a positive integer value less than 65,000
    • Read an input number from the user.
    • Repeat the request until the user has entered a correct value.
  • Based on the decimal value entered by the user, print out the binary equivalent.
    • Program a while loop to iterate down over all the powers of 2, starting with 216
      • Create a variable called exponent and initalize it to 16.
      • use the pow(2,exponent) function in C to calculate 2 to that power.
      • Divide the user's number by that power of 2 to get the binary digit in that position.
      • Print out the digit
      • If the digit * (power of 2) is less than the user's number, subtract it from the user's number.
      • Decrement the exponent.