EP100 MidSemesterTest S12010 Ans
EP100 MidSemesterTest S12010 Ans
1. The following C program contains 5 (five) syntax errors. State the line numbers of
where the errors occur (1 mark each) and rectify these errors (1 mark each).
[10 marks]
Ans:
b. Logical error is an error caused by improper logic in code for any operation
Control and Repetition
The program should display on the screen a prompt for the radius in metres. The user
should enter this radius value at the keyboard, from which the program should read it.
The program should than check if the radius value is valid (i.e. positive values). If the
value is not valid, it shall continuously prompt the user until a valid value is entered.
The program should than ask for the units of the displayed results for the
circumference and area. The selectable units are metres (m and m2), centimetres (cm
and cm2) and millimetres (mm and mm2). The user should than enter one of this
selection at the keyboard, from which the program should read it. The program should
than check if the selection is valid. If it is not valid, it shall continuously prompt the
user until a valid selection is entered. The program should than proceed to compute
the circumference and area of the circle given the radius value and display the results
according to the selected unit.
int main()
{
float radius; // 2 marks for variable with correct data types
float area, circumference;
int unit;
float conversion_m_cm=100; // 2 marks for conversion terms
float conversion_m_mm=1000;
return 0;