| School of Physics |
|
| Physics Home | Study here | Our Teaching | Our Research | Our Centres | News | Work here | EMPS |
Back to top
Week 3 ExercisesThese exercises are assessed. Remember
When it says hand in below, that means the code and a sample of the output. If you get stuck email your code to me as plain text (copy and paste it into your email). The if() statementRevise the two ways we wrote the "positive/negative, odd/even" if code (nested ifs and else ). Chose the method you think is simpler for the next task. ExerciseExtend your quadratic code, still assuming real coefficients, but handling all of the possible cases: both a and b equals zero (invalid equation), a equals zero with b non-zero (linear equation), and all three possible conditions on the discriminant (postive, zero, negative). Construct a suitable if statement to handle them all, checking that the result is correct in each case. I strongly recommend you write this a bit at a time. Get one case working, and check it, before starting on the next. Using the while() loopTipTo see what your while() loop is doing (for example, if it's not behaving as you would wish), have a printf() statement inside the loop that prints out the names and values of all the relevant variables. Exercise
|