You are on page 1of 3

CS113: Introduction to Programming Page 1

Department of Computing



CS113: Introduction to Programming
Class: BEE-6-AB
Lab 4 Expressions and Operators
Date: 1
st
October, 2014
Instructor: Ms. Samin Khaliq












CS113: Introduction to Programming Page 2



Lab 4 Expressions and Operators
Instructions
Complete the tasks below and save them on computer. Insert the solution/answer in this
document as directed below. You must show the execution of below tasks, along with your
completed Word document to get your work graded. You must also submit this Word document
on the LMS.

Deliverables
Compile a single Word document by filling in the solution/answer part and submit this Word file
on LMS.
This lab is graded. Min marks: 0. Max marks: 10.
Lab Tasks
Q1) Write a program that asks the user to enter a three-digit number, then prints the sum of its
digits. A session with the program should have the following appearance:
Enter a three-digit number: 128
The sum is: 11
Read the number using the %d, then break it into three digits. Hint: If n is a two-digit integer,
then n%10 is the last digit in n and n/10 is n with the last digit removed.


Answer:
Solution: Code


Q2) Two numbers are input through the keyboard into two locations var1 and var2. Write a
program to interchange (i.e. swap) the contents of var1 and var2. Your program should then
display the swapped values.


Answer:

Solution: Code

CS113: Introduction to Programming Page 3




Q3) Saleems basic salary is input through the keyboard. His dearness allowance is 40% of
basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate
and display the allowances and his gross salary. Store the allowances & gross salary in float
variables?

Answer:
Solution: Code


Q4) If the marks obtained by a student in five different subjects are input through the
keyboard, write a program to find out the aggregate marks and average marks obtained by the
student. Assume that the maximum marks that can be obtained by a student in each subject
are 100.
Try using an int variable for storing the average marks and observe the behavior. What is the
difference if you store the average marks in a float variable?

Answer:

Solution: Code

You might also like