Amrita School of Computing
23CSE201 Procedural Programming using C
Lab Exercise 1 – IO, Datatypes, and Operators
CO2 Design and implement computer program using suitable programming constructs.
Simple IO and Arithmetic Operators
Define Constants wherever possible.
1. Write a C Program to calculate the volume of a pool. The equation for determining the
volume is:
Volume = length x width x depth.
Assume that the pool has a length of 25.5 feet, a width of 10.6 feet, and a depth of 6.4
feet. Initialise the variables, compute the volume, and display the result in a well-
formatted output.
2. Write a C program that prompts the user to enter five numbers, then calculates their
sum. Using this sum, determine the percentage contribution of each number to the
total.
Additionally, compute the average of the five numbers. Finally, display the sum, the
percentage of each number, and the average in a clear and well-formatted manner.
3. Use the sizeof() operator in C and display the size in number of bits and total bytes
for each of the following data types:
a. char
b. unsigned char
c. short int
d. unsigned short int
e. int
f. unsigned int
g. long int
h. unsigned long int
i. long long int
j. unsigned long long int
k. float
l. double
m. long double
n. Fixed-width integer types (from <stdint.h> ): (Optional)
i. int8_t
ii. uint8_t
iii. int16_t
iv. uint16_t
v. int32_t
vi. uint32_t
vii. int64_t
viii. uint64_t
Page 1 of 3
Amrita School of Computing
23CSE201 Procedural Programming using C
4. Write a C program that:
a. Reads the radius of a sphere from the user
b. Calculates the surface area using the formula : 4×π×r2
c. Compute its volume using: (4/3)×π×r2
5. Write a C program to calculate the Gravitational Potential Energy (PE) of an object
in joules. The formula for calculating PE is:
PE=m×g×h
where:
m = mass of the object (in kilograms)
g = acceleration due to gravity (9.8 m/s²)
h = height of the object above the ground (in meters)
Your program should take mass and height as inputs from the user, compute the PE,
and display the result in joules.
6. Read two integers from the user and perform the following operations using <math.h>
functions wherever mentioned:
a. Sum — a+b
b. Difference — a−b
c. Product — a×b
d. Quotient (Integer Division) — a/b
e. Quotient (Floating-Point Division) — a/b with decimal precision
f. Remainder — a%b
g. Power — a^b using pow()
Print decimal precision values for the following
h. Square Root of a — using sqrt()
i. Natural Logarithm of a — using log()
j. Sine of a (in radians) — using sin()
Refer: https://cplusplus.com/reference/cmath/
Display the result of each operation with a clear label, with proper formatting.
7. Implement C code to evaluate and print(formatted) the value of the following
expression:
Hint: In C, scientific notation is represented using e or E.
e.g, for 3.8 * 1040 can be assigned to a variable as
double v = 3.8e40.
Page 2 of 3
Amrita School of Computing
23CSE201 Procedural Programming using C
Relational and Logical Operators
Note: In C, relational operators (==, !=, >, <, >=, <=) are used to compare two
expressions and return 1 if the relation is true, otherwise 0.
Logical operators in C (&&, ||, !) operate on these truth values to combine or negate
conditions for decision-making in programs.
8. Read three values from the user and print the result of the following expressions:
a. (a > 0 && b > 0 && c > 0)
b. (a > 0 && (b < 0 || c < 0))
c. (a > b || b > c)
d. (a == b && b == c)
e. (a != b || b != c || a != c)
f. (a%2 == 0 && b%2!= 0 && c%2 == 0)
g. ((a + b) > c && (b + c) > a && (a + c) > b)
h. !(a == 0 || b == 0 || c == 0)
i. !a||(b=7)
Try out various combinations of each value of a, b, and c.
9. Write a program to input principle, rate and time and display simple interest and the
total amount to pay.
SI = (p x r x t)/100
10. Write a C program to read two-point values represented by x1, y1and x2,y2 calculate
the distance between two points.
11. Write a C program that reads two numbers from the user and swaps their values.
After swapping, display the numbers before and after the swap.
12. Write a C program that accepts an employee's ID, total worked hours in a month and
the amount he received per hour. Print the employee ID and salary (with two decimal
places) of the employee for a particular month.
Bitwise Operators
13. Write a C program to accept two unsigned integers from the user and display the
results of applying all bitwise operators on them. Display the results using %u and
%d.
Bitwise NOT of x
Bitwise AND of x and y
Bitwise OR of x and y
Bitwise XOR of x and y
Left shift x by 2 positions
Right shift x by 2 positions
Bitwise NOT of y
Left shift y by 2 positions
Right shift y by 2 positions
Page 3 of 3