[Previous Homework]
[Next Homework]
From Linux on the GL machine:
Using the dectobin.c code as a template, create a program that does the following:
Make sure that you follow all the coding standards
hw07 - Conditional Statements 1
From Linux on the GL machine:
-
Write a C program (see below) and save it in a file called dectobin.c in your ./cmsc104/hw07 directory
Compile the program:
gcc -o dectobin dectobin.c
Run the program to make sure it works:
./dectobin
Use the SUBMIT utility turn in the homework.
submit cs104_grasso hw07 dectobin.c dectobin
Using the dectobin.c code as a template, create a program that does the following:
-
Create a function name
DecToBin
that does the following:
-
Prompt the user to enter a number between 0 and 1024
Echo the value back to the user
Check to see if the value is in range. If not, print an error message and return -1 from the function to indicate failure
Convert that decimal value to it's equivalent in binary
-
Divide the decimal number by 210 (1024)
If the result is 0
-
print a 0 (leave out the \n newline character)
-
print a 0 (leave out the \n newline character)
subtract 1024 from the original number
Make sure that you follow all the coding standards