Rajarata University of Sri Lanka
Rajarata University of Sri Lanka
Department of Computing
1. Write a program that subtracts the value 15 from 87 and displays the result, together with
an appropriate message, at the terminal.
2. Identify the syntactic errors in the following program. Then type in and run the corrected
program to ensure you have correctly identified all the mistakes.
#include <stdio.h>
int main (Void)
(
INT sum;
/* COMPUTE RESULT
sum = 25 + 37 – 19
/* DISPLAY RESULTS //
printf ("The answer is %i\n" sum);
return 0;
}
#include <stdio.h>
int main (void)
{
int answer, result;
answer = 100;
result = answer - 10;
printf ("The result is %i\n", result + 5);
return 0;
}
Page 1 of 4
4. Which of the following are invalid variable names? Why?
#include <stdio.h>
int main (void)
{
char c, d;
c = 'd';
d = c;
printf ("d = %c\n", d);
return 0;
}
Page 2 of 4
14. Write a program that converts inches to centimeters. For example, if the user enters 16.9
for a Length in inches, the output would be 42.926cm. (Hint: 1 inch = 2.54 centimeters.)
15. The figure gives a rough sketch of a running track. It has a rectangular shape and two
semi-circles. The length of the rectangular part is 67m and breadth is 21m. Calculate the
distance of the running track.
For the following program, use the keyboard to input data and apply the appropriate format
modifiers.
16. Write a program to swap two numbers without using a third variable.
17. Write a program to calculate the area of a circle given the radius.
18. Write a program to reverse a given 3-digit number.
19. Write a program to calculate the area of a rectangle given its length and width.
20. Write a program to convert hours to minutes.
21. Write a program to convert kilometers to meters.
22. Write a program to calculate the area of a triangle given its base and height.
23. Write a program to calculate the simple interest given principal, rate, and time.
24. Write a program to calculate the cost of painting a wall given its area and cost per square meter.
25. Write a program to calculate the total marks and average given marks in 5 subjects.
26. Write a program to find the price of 1 item given the price for a dozen.
27. Write a program to calculate the total distance covered given speed and time.
28. Write a program to calculate the weight of an object on the Moon given its weight on Earth
(Moon's gravity is 1/6th of Earth's).
29. Write a program to calculate the volume of a cube given the side length.
30. Write a program to read a string and display it.
31. Write a program to calculate the speed of an object using the formula: speed = distance /
time.
32. Write a program to calculate the force using the formula: force = mass * acceleration.
33. Write a program to calculate the kinetic energy using the formula: KE = 0.5 * mass *
velocity^2.
Page 3 of 4
34. Write a program to calculate the potential energy using the formula: PE = mass * gravity
* height.
35. Write a program to calculate the pressure using the formula: pressure = force / area.
36. Write a program to calculate the work done using the formula: work = force * distance.
37. Write a program to calculate the volume of a sphere using the formula: volume = (4/3) *
pi * radius^3.
38. Write a program to calculate the density using the formula: density = mass / volume.
39. Write a program to calculate the power using the formula: power = work / time.
40. Write a program to calculate the energy of a photon using the formula: energy =
Planck_constant * frequency.
Page 4 of 4