Physics and Astronomy |
Back to top
On this page
Contents Function exercisesThese form an important part of your learning but are not formally assessed as a part of your course mark. Bring them to a demonstrator next week for feedback.The aims at the moment are for you:
At this stage all of your functions should appear inside main.c . Maximum functionWrite a function that accepts two double arguments and returns the maximum of the two. Now write a simple main() function after this function (i.e. further down main.c than the function you have just written) that calls it for several pairs of values and prints out the result. Add a prototypeNow reorder your functions so that main() appears before your maximum function. As it stands this causes a problem as there is no prototype: create such a prototype and place it between the #include directives and the first function. Fizz Buzz in a functionAlthough it's not ideal, we all find ourselves needing to use some code that was in the middle of main(), or another function, more than once. As mentioned in the lecture it's important not to just copy and paste more than a few lines of code but to make them into a function instead.
|