Chapter 3 Worksheet
Chapter 3 Worksheet
FLOW OF CONTROL
[SET – 1]
Question 1 Any integer is input by the user. Write a program to find out whether it is
an odd number or even number.
Question 2 Find the absolute value of a number entered by the user.
Question 3 Write a program to calculate the total expenses. Quantity and price per
item are input by the user and discount of 10% is offered if the expense is
more than 5000.
Question 4 Write a program to determine whether the seller has made profit or
incurred loss. Also determine how much profit he made or loss he
incurred. Cost price and selling price of an item is input by the user.
Question 5 If the ages of Ram, Sulabh and Ajay are input by the user, write a
program to determine the youngest of the three.
Question 6 Write a program to check whether a triangle is valid or not, when the
three angles of the triangle are entered by the user. A triangle is valid if
the sum of all the three angles is equal to 180 degrees.
Question 7 Any year is input by the user. Write a program to determine whether the
year is a leap year or not.
Question 8 In a company an employee is paid as under:
If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary
and DA = 90% of basic salary.
If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500
and DA = 98% of basic salary.
If the employee's salary is input by the user write a program to find his
gross salary.
Question 9 Write a program to calculate the monthly telephone bills as per the
following rule:
Minimum Rs. 200 for upto 100 calls.
Plus Rs. 0.60 per call for next 50 calls.
Plus Rs. 0.50 per call for next 50 calls.
Plus Rs. 0.40 per call for any call beyond 200 calls.
Question 10 Write a program to find the roots of and quadratic equation of type
ax2+bx+c where a is not equal to zero.
Question 11 The marks obtained by a student in 5 different subjects are input by the
user. The student gets a division as per the following rules:
Percentage above or equal to 60 - First division
Percentage between 50 and 59 - Second division
Percentage between 40 and 49 - Third division
Percentage less than 40 - Fail
Write a program to calculate the division obtained by the student.
FLOW OF CONTROL
[SET – 2]
Question 1 Write a program to print number from 1 to 10.
Question 3 Write a program to find the factorial value of any number entered through the
keyboard.
Question 4 Two numbers are entered through the keyboard. Write a program to find the
value of one number raised to the power of another.
Question 9 Write a program to enter the numbers till the user wants and at the end it
should display the count of positive, negative and zeros entered.
Question 10 Write a program to enter the numbers till the user wants and at the end it
should display the maximum and minimum number entered.
Question 11 Write a program to print out all Armstrong numbers between 1 and 500. If
sum of cubes of each digit of the number is equal to the number itself, then
the number is called an Armstrong number.
For example 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 )
Question 12 Write a program to print Fibonacci series of n terms where n is input by user :
0 1 1 2 3 5 8 13 24 .....
Laboratory worksheet
1. Write a C++ program, which inputs ten numbers and display largest number using any loop
statement:
2. Write a C++ program that displays a square filled with. In addition, whose borders are made of x
and whose size does the user give. For example if the user enters five, he/she will obtain:
X X X X X
X X
X X
X X
X X X X X
3. Write a program that display the 10 first terms of the Fibonacci sequence using any loop.
4. Receive three numbers and display them in ascending order from smallest to largest.
5. Write a program, which reads a floating-point number the print the integer and fraction of that
number:
6. Add the even numbers between 0 and any positive integer number given by the user.
7. Take an integer from the user and display the factorial of that number. Use for loop.
8. Write and run a program that reads a positive integer n and then prints a diamond of asterisks. Use
for loop. For example, if n is 4, then the output would be
*
* * @@@@ x x
*** @@@
** ** x x
***** *** *** @@ x
**** **** @ x x
*******
x x
*****
***
*
9. Find the absolute value of any number using any selection statement.
10. Write an application to print out the numbers 10 through 49 in the following manner
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
1 1 1 4321
22 21 12 321
333 321 123 21
4444 4321 1234 1
FLOW OF CONTROL
[SET – 3]
Question 1
i) ********** ii) * iii) *
********** ** **
********** *** ***
********** **** ****
***** *****
iv) * v) 1 vi) 1
*** 222 212
***** 33333 32123
******* 4444444 4321234
********* 555555555 543212345
Question 2 Write a program to compute sinx for given x. The user should supply x and a
positive integer n. We compute the sine of x using the series and the
computation should use all terms in the series up through the term involving xn
Question 3 Write a program to compute the cosine of x. The user should supply x and a
positive integer n. We compute the cosine of x using the series and the
computation should use all terms in the series up through the term involving xn