Your First C Program
For this assignment, you will write a C program called
This program reads two numbers from the user,
and produces a few arguably-interesting facts about the numbers.
See the example output for the exact output expected from your program.
- Read the two numbers.
- Display the result of dividing the first number by the second one,
using floating-point division.
What if the second number is zero? Check the examples.
- Display the numbers in increasing order.
- If either number is thirteen, note that.
- Display which numbers are odd.
This one is tricky. Look carefully at the examples, below.
What should you print if one is odd and one isn’t?
What if both are odd?
For the record: 13, 3, and -27 are odd; 6, 18, 0, and -90 are not.
Here are a few example runs of the program. The “
% ” is the command
prompt, text like this is typed by the user, and the rest is from
the program. (You don’t have to make it colored or underlined—that’s
just how it looks here, so you can tell who does what.) Don’t be
creative about your output—it must look exactly like this (except for
the leading spaces):
% c11 -Wall nums.c
A couple of numbers, if you please: 123456 13
Division of 123456 by 13: 9496.615385
In order: 13 123456
A couple of numbers, if you please: 1 2
Division of 1 by 2: 0.500000
In order: 1 2
A couple of numbers, if you please: 13 -18
Division of 13 by -18: -0.722222
In order: -18 13
A couple of numbers, if you please: 0 42
Division of 0 by 42: 0.000000
In order: 0 42
A couple of numbers, if you please: 0 0
Division of 0 by 0: nope!
In order: 0 0
A couple of numbers, if you please: -5 0
Division of -5 by 0: nope!
In order: -5 0
A couple of numbers, if you please: 13 13
Division of 13 by 13: 1.000000
In order: 13 13
Odd: 13 13
A couple of numbers, if you please: 301 9
Division of 301 by 9: 33.444444
In order: 9 301
Odd: 301 9
A couple of numbers, if you please: 9 301
Division of 9 by 301: 0.029900
In order: 9 301
Odd: 9 301
If you encounter “STACK FRAME LINK OVERFLOW”, then try this:
- You must turn in the
.c file; not the binary,
not the executable, not the
- We will only test your code with integer input,
and their absolute values will be less than one million.
- The division must be performed with double-precision arithmetic.
- The quotient must be displayed with six places after the decimal point.
- You may use only two
int variables, declared in
in your entire program. No other variables, of any type, are allowed.
- Yes, really.
- We will test your program with several different sets of numbers,
not necessarily those listed above.
- You must comment your code appropriately, including your name,
date and purpose of the program at the very very very beginning of the file.
- Your output should be exactly the same as the examples above,
given the input as specified.
A Brief Conversation About Requirements
- Adhere to the above requirements, exactly.
- Uppercase/lowercase, spacing, punctuation,
etc. must be identical to the samples above.
- The grading software will flag any deviations and points will be deducted.
- Originality is not rewarded.
How to submit your homework:
Use web checkin, or:
~cs156/bin/checkin HW1 nums.c
How to receive negative points:
Turn in someone else’s work.
- Our grading software compares student submissions for similarity, including obfuscation.
- Sharing ideas and talking about the assignment or the C language is good. That is part of learning.
- Sharing your code or viewing each other's screens is not.