Lab_02
Lab_02
operators in C language.
1. Write a C program to perform the following operations. (Not: Add header comments and the
program comments when necessary.)
• Create an integer variable called as age.
• Assign your age to the age integer variable.
• Print the value of the age variable.
Upload the completed program into lab 02 –Program 01 folder in the CAL.
2. Write a C program perform the following tasks. (Not: Add header comments and the program
comments when necessary.)
• Create variables to store the following information:
o Your birth year. o A/L Z-Score.
o Your Letter grade for the A/L Physics or any other
subject (A, B, C).
• Assign the values to each variable you have declared in the previous step.
• Print the values of each variable in separate line.
Upload the completed program into lab 02 – Program 02 folder in the CAL.
Write output statements that would produce the output below (notice that the values stored in
the variables have been output):
Test Score 1 = 90
Test Score 2 = 80
The sum of the scores = 170
Upload the completed program into lab 02 – Program 03 folder in the CAL.
1
4. Write the following C program.
return 0;
}
Upload the completed MS Word into lab 02 – Program 04 folder in the CAL.
5. Write a C program to print the memory allocation of all the basic datatypes.
Hint: Use the sizeof function to find the memory allocation of a give data type:
Eg:
int intsize = (int) sizeof(int);
Upload the completed program into lab 02 – Program 05 folder in the CAL.
Hints:
- To find the above information, you might need to include the following C standard
libraries: <limits.h> and <float.h>.
- Use the following constants to find the relevant maximum and minimum in each data
types.
INT_MAX, INT_MIN, FLT_MAX, -FLT_MAX, DBL_MAX, DBL_MIN
Upload the completed program into lab 02 – Program 06 folder in the CAL.
2
7. Write a C program to determine an employee weekly salary based on the following
information.
• Employee regular hourly pay rate is Rs. 250.00.
• Employee overtime pay rate is Rs. 300.00.
• Assume that employee worked 40 regular working hours and 15 overtime hours.
• Then, calculate the total weekly pay for the employee and display it with an
appropriate message. (Note: In this program, you do not need to consider the if else
statements.)
Upload the completed program into lab 02 – Program 07 folder in the CAL.
8. Write a C program to find the results of the following expressions. Display the result of each
expression separately.
201 % 12
122 % 3
5005 % 103
100005 % 23
2085 % 13
Upload the completed program into lab 02 – Program 08 folder in the CAL.
9. Consider the partially completed C program below. Complete the blanks in the program and
write a complete C program to determine the cost of renting a boarding place for number of
years.
//preprocessor section
# ____________
__________ main ()
{
//constants declarations
__________ int RENT_RATE = 350;
3
________("The number of years is: ______",_______);
________("The total cost of rent is: ______",_______);
__________
______
Upload the completed program into lab 02 – Program 09 folder in the CAL.
10. Write a C program to determine the area and the circumference of a circle of radius 12.
For the above calculations, create PI as a constant and assign the value 3.14519 to it.