Week 02 Extra Exercises
Information
- This page contains extra exercises for week 02.
- These exercises are not compulsory, nor do they provide any marks in the course.
- You cannot submit any of these exercises, however autotests are available for them (Command included at bottom of each exercise).
Exercise
(●◌◌)
:
Ordering Three Integers
Write a C program order3.c
using if statements (no loops)
that reads 3 integers and prints them from smallest to largest.
Examples
dcc order3.c -o order3 ./order3 Enter integer: 23 Enter integer: 5 Enter integer: 27 The integers in order are: 5 23 27 ./order3 Enter integer: 3 Enter integer: 6 Enter integer: 27 The integers in order are: 3 6 27 ./order3 Enter integer: 9 Enter integer: 8 Enter integer: 7 The integers in order are: 7 8 9
You can assume the user supplies 3 integers. You do not have to check the return value from scanf.
When you think your program is working,
you can use autotest
to run some simple automated tests:
1091 autotest order3