0% found this document useful (0 votes)
6 views

Lab_02

C programming
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)
6 views

Lab_02

C programming
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

Throughout this lab session, you will learn variables, primitive (basic) data types and arithmetic

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.

3. Write a C program contains the following variable declarations and assignments:

int test1Score = 90; int


test2Score = 80;
int sumOfScores = test1Score + test2Score;

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.

int main() { int


a = 25; float b =
45.0; char c =
‘A’; float sum;
sum = a + b + c;
printf(“Result = %f\n”, sum);

return 0;
}

In a MS Word document write the answers to the following questions:


- What is the output of the above
program? - Explain reasons for the above
output.

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.

6. Write a C program to find the following information:


• Maximum and minimum number that can be stored in int data type.
• Maximum and minimum number that can be stored in float data type.
• Maximum and minimum number that can be stored in double data type.

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.

/*This program determines the cost for renting a boarding


place for a set number of years.*/

//preprocessor section
# ____________

__________ main ()
{

//constants declarations
__________ int RENT_RATE = 350;

int years = 3; //# of years over which rent is computed


int costOfRent____ //cost for renting

//calculate the rent costOfRent =


years * RENT_RATE;

//output the results


________("The cost per month for rent is: ______",_______);

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.

𝐴𝑟𝑒𝑎 𝑜𝑓 𝑎 𝑐𝑖𝑟𝑐𝑙𝑒 = 𝜋𝑟!

Circumference of a circle = 2πr

For the above calculations, create PI as a constant and assign the value 3.14519 to it.

You might also like