Lab 2&3
Lab 2&3
Example 2.2:
Write a program to assign two variables by assignment statement.
Interchange the values and print the result on the screen.
Example 2.3
Write a program to print a message on screen by using “endl” manipulator.
Example 2.4
Write a program in C++ to get two numbers from keyboard during program
execution. Calculate the sum and product of the numbers and then print the
result on the computer.
LAB REVIEW QUESTIONS
Question No1
Write a program in C to print out your name on the output screen
Question No 2
Write the program in C to print the area of circle on the output screen
Question No 3
Write a program in C to add any three numbers and print the result on
output screen.
Question No 4
Write a program in C to get three numbers from user and perform addition
and multiplication.
Question No 5
Write a program in C to assign numeric value to variable year and calculate
the months
LAB No. 03
If statement and If else statement
LAB Exercise Programs
Example 3.1
Write a program to assign value in any variable and check whether it is less
than 20 or not
Example 3.2
Write a program to assign value in to variable ‘a’ and check whether it is
less than 20 or not using if else statement
Example 3.3
Write a program to read three integer numbers then find and print the
largest one among these numbers.
Example 3.4
Write a program that determines a student’s grade. The program will read
three types of scores (quiz, mid-term, and final scores) and determine the
grade based on the following rules: if the average score =90% =>grade=A if
the average score >= 70% and <90% => grade=B if the average score>=50%
and <70% =>grade=C if the average score<50% =>grade=F
Example 3.5
Write a program that prompts the user for the current year, the user's
current age, and another year. It then calculates the age that the user was or
will be in the second year entered
Example 3.6
Write a program to executes a single statement if the given condition is true
Example 3.7
Write a program to calculate the electricity bill. The rates of electricity per
unit are as follow If the units consumed are equal or less than 300, then the
cost is Rs 3/ per unit If units consumed are more than 300, then the cost is
Rs. 3.5/- per unit and a surcharge of 5% of bill is added.