Skip to content
Physics and Astronomy
Home Our Teaching Resources C programming Exercises
Back to top

NB: The exercises are quite short this week as there is an aassessed assignment on the ELE page.

Exercises: variables and expressions

Exercises 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 aim at the moment is for you to be able to use the % operator and simple arithmetic, including complex numbers.

Complex Nth-roots

Write a program that uses complex numbers to calculate the Nth root of an arbitrary real number (including the posibility of the number being negative), where N is an integer. Print out the number and the root. You may ignore the possibility that N is zero.

Now write a test that calculates the result to the Nth power and prints out the absolute value of the difference between this and the original value.


Validate   Link-check © Copyright & disclaimer Privacy & cookies Share
Back to top