- using complex if statements to control program execution
- using a while loop for repetition
- input & output of numerical values
- implementing simple numerical calculations

Create a new directory for this lab called `lab03`

by typing:

Change to this directory by typing:mkdir lab03

cd lab03

`order3.c`

using Your program should behave exactly like this example:

You can assume the user supplies 3 integers. You do not have to check the return value from scanf../order3Enter integer:23Enter integer:5Enter integer:27The integers in order are: 5 23 27./order3Enter integer:3Enter integer:6Enter integer:27The integers in order are: 3 6 27./order3Enter integer:9Enter integer:8Enter integer:7The integers in order are: 7 8 9

When you think you have `order3.c`

working use autotest to test it further:

~cs1511/bin/autotest lab03 order3.cTest order3_0 (1 2 3) - passed Test order3_1 (99 50 1) - passed Test order3_2 (45 99 87) - passed Test order3_3 (100 4 45) - passed Test order3_4 (50 60 20) - passed Test order3_5 (50 30 90) - passed Test order3_6 (20 20 20) - passed Test order3_7 (20 20 30) - passed Test order3_8 (30 30 20) - passed Test order3_9 (30 20 30) - passed

`is_leap_year.c`

that reads a year
and then
prints whether that year is a leap year.
Match the examples below exactly

Hint: you only need use the **int** type, modulus (**%**) and **if** statement(s).

Hint: if you are clever with **&&** and **||** it just needs one if statement.

For example:

When you think you havedcc -o is_leap_year is_leap_year.c./is_leap_yearEnter year:20172017 is not a leap year../is_leap_yearEnter year:20162016 is a leap year../is_leap_yearEnter year:20002000 is a leap year../is_leap_yearEnter year:30003000 is not a leap year.

`is_leap_year.c`

working use autotest to test it further:
~cs1511/bin/autotest lab03 is_leap_year.cTest is_leap_year_0 (2020) - passed Test is_leap_year_1 (2019) - passed Test is_leap_year_2 (2018) - passed Test is_leap_year_3 (2017) - passed Test is_leap_year_4 (2016) - passed Test is_leap_year_5 (2000) - passed Test is_leap_year_6 (2100) - passed Test is_leap_year_7 (1900) - passed Test is_leap_year_8 (1800) - passed Test is_leap_year_9 (1000) - passed

`cubes.c`

that reads a positive integer
Your program should print **exactly** this output:

Make sure your program matches the above output./cubesEnter how many cubes: 4 1^3 = 1 2^3 = 8 3^3 = 27 4^3 = 64./cubesEnter how many cubes: 16 1^3 = 1 2^3 = 8 3^3 = 27 4^3 = 64 5^3 = 125 6^3 = 216 7^3 = 343 8^3 = 512 9^3 = 729 10^3 = 1000 11^3 = 1331 12^3 = 1728 13^3 = 2197 14^3 = 2744 15^3 = 3375 16^3 = 4096

As usual autotest is available to help you test your program.

~cs1511/bin/autotest lab03 cubes.c

`leap_years.c`

that reads a start year and finish year
and then
prints all the leap years that lie in that range.
Match the examples below exactly

Hint: you only need use the `int`

type, modulus (%) and a `while`

loop.

For example:

When you think you have./leap_yearsEnter start year:1995Enter finish year:2020The leap years between 1995 and 2020 are: 1996 2000 2004 2008 2012 2016 2020./leap_yearsEnter start year:1780Enter finish year:1813The leap years between 1780 and 1813 are: 1780 1784 1788 1792 1796 1804 1808 1812./leap_yearsEnter start year:997Enter finish year:1003The leap years between 997 and 1003 are:

`leap_year.c`

working use autotest to test it further:
~cs1511/bin/autotest lab03 leap_years.cTest 23 (1980 2020) - passed Test 24 (1492 1508) - passed Test 25 (1770 1810) - passed Test 26 (4444 5555) - passed

`sum_cubes.c`

that reads a positive integer
Your program should print **exactly** this output:

Make sure your program matches the above output./sum_cubesSum how many cubes?41^3 + 2^3 + 3^3 + 4^3 = 100./sum_cubesSum how many cubes?101^3 + 2^3 + 3^3 + 4^3 + 5^3 + 6^3 + 7^3 + 8^3 + 9^3 + 10^3 = 3025./sum_cubesSum how many cubes?161^3 + 2^3 + 3^3 + 4^3 + 5^3 + 6^3 + 7^3 + 8^3 + 9^3 + 10^3 + 11^3 + 12^3 + 13^3 + 14^3 + 15^3 + 16^3 = 18496./sum_cubesSum how many cubes?11^3 = 1

As usual autotest is available to help you test your program.

~cs1511/bin/autotest lab03 sum_cubes.c

`one_loop_square.c`

that reads an integer and prints a square of asterisks that size.
In lectures we cover how to solve this using nested while loops and three variables.

In this challenge exercises, you are only permited to use a single **while** loop and only two variables which must be of type **int**.

You are not permitted to call functions other than printf and scanf. For example, you are not permitted to use functions from the math library.

You are only permitted to use parts of C covered in the weeks 1 and 2 lectures.

Your program should behave exactly like this example:

This is as much a puzzle as a programming exercise but the techniques you need to use can be useful elsewhere../one_loop_squareSquare size:1*./one_loop_squareSquare size:2** **./one_loop_squareSquare size:7******* ******* ******* ******* ******* ******* *******

Autotest is available to help you test your program - but it doesn't check that your code meets the above restrictions.

~cs1511/bin/autotest lab03 one_loop_square.c

`order3_challenge1.c`

that reads 3 integers and prints them from smallest to largest.
You are not permitted to use **if** statements.

You are not permitted to use loops (e.g. **while**).

You are not permitted to call functions other than printf and scanf. For example, you are not permitted to use functions from the math library.

You are not permitted to use printf inside expressions - you can only use printf as a statement (the way it has been used in lectures).

You are not permitted to use **printf** inside expressions - you can only use **printf** as a statement (the way it has been used in lectures). You can use **printf** to print the value of an expression, in other words you can have an
expression inside **printf**.

You are only permitted to use parts of C covered in the weeks 1 and 2 lectures. For example, you are not permitted to use the ternary ?: operator. You are not permitted to define functions.

Your program should behave exactly like this example:

This is more puzzle than a programming exercise../order3_challenge1Enter integer:23Enter integer:5Enter integer:27The integers in order are: 5 23 27./order3_challenge1Enter integer:3Enter integer:6Enter integer:27The integers in order are: 3 6 27./order3_challenge1Enter integer:9Enter integer:8Enter integer:7The integers in order are: 7 8 9

Try to invent your own solution - don't google or ask others how do it. Tutors will reward interesting, original or weird approaches even if they don't work.

Autotest is available to help you test your program - but it doesn't check that your code meets the above restrictions.

~cs1511/bin/autotest lab03 order3_challenge1.c

`order3_challenge2.c`

that reads 3 integers and prints them from smallest to largest.
You are only permitted to have 3 variables in your program and they must be of type **int**.

The restrictions of the previous challenge exercise also apply.

You are not permited to use **if** statements.

You are not permitted to use loops (e.g. **while**).

You are not permitted to call functions other than printf and scanf. For example, you are not permitted to use functions from the math library.

You are not permitted to use **printf** inside expressions - you can only use **printf** as a statement (the way it has been used in lectures). You can use **printf** to print the value of an expression, in other words you can have an
expression inside **printf**.

You are only permitted to use parts of C covered in the weeks 1 and 2 lectures. For example, you are not permitted to use the ternary ?: operator. You are not permitted to define functions.

Your program should behave exactly like this example:

This is much more puzzle than a programming exercise../order3_challenge2Enter integer:23Enter integer:5Enter integer:27The integers in order are: 5 23 27./order3_challenge2Enter integer:3Enter integer:6Enter integer:27The integers in order are: 3 6 27./order3_challenge2Enter integer:9Enter integer:8Enter integer:7The integers in order are: 7 8 9

Try to invent your own solution - don't google or ask others how do it. Tutors will reward interesting, original or weird approaches even if they don't work.

Autotest is available to help you test your program - but it doesn't check that your code meets the above restrictions.

~cs1511/bin/autotest lab03 order3_challenge2.c

`lab03`

directory):
Submit the challenge exercises only if you attempt them.give cs1511 lab03 order3.c is_leap_year.c cubes.c leap_years.c sum_cubes.c one_loop_square.c order3_challenge1.c order3_challenge2.c

If you are working at home, you may find it more convenient to upload your work via give's web interface.

Remember the lab assessment guidelines - if you don't finish the exercises
you can finish them in your own time, submit them
by Monday 11:00am using `give`

and ask your tutor to assess them at the start of
the following lab.

Either or both members of a programming pair can submit the work (make sure each program lists both of you as authors in the header comment).