0% found this document useful (0 votes)
21 views4 pages

Rajarata University of Sri Lanka

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Rajarata University of Sri Lanka

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Rajarata University of Sri Lanka

Department of Computing

ICT 1402 – Principles of Program Design and Programming


Tutorial 05

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;
}

3. What output you might expect from the following program?

#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?

Int char 6_05


Calloc Xx alpha_beta_routine
floating _1312 z
ReInitialize _ A$

5. Which of the following are invalid constants? Why?

123.456 0x10.5 0X0G1


0001 0xFFFF 123L
0Xab05 0L -597.25
123.5e2 .0001 +12
98.6F 98.7U 17777s
0996 -12E-12 07777
1234uL 1.2Fe-7 15,000
1.234L 197u 100U
0XABCDEFL 0xabcu +123

6. What output would you expect from the following program?

#include <stdio.h>
int main (void)
{
char c, d;
c = 'd';
d = c;
printf ("d = %c\n", d);
return 0;
}

Write C Programs for the requirements given below

7. Convert given value in Meter to centimeter.


8. Calculate the volume of a cylinder. PI * r2 h
9. Calculate average marks of 4 subjects which, entered separately.
10. Convert the given temperature in Celsius to Fahrenheit. T(°F) = T(°C) × 1.8 + 32
11. Find the value of y using y = 3.5x+5 at x = 5.23.
12. Find the cost of 5 items if the unit price is 10.50 Rupees.
13. Enter the name, height, weight and gender of a person and calculate his/her BMI in Kg.
BMI = weight/ height2

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

You might also like