118 Programming and Data Structures
simple and easy way. Simple & ample examples have been explained on decision-making statements.
To change the flow of the program the programmer can use statements such as b r e a k , continue and
goto. The Reader is expected to execute all the programs given in this chapter so as to achieve the
expertise in handling decision-making statements in the programs. If more real life problems are
writen by the programmer then it becomes beneficial.
EXERCISES
A) Answer the following questions
1) Is it possible to use multiple else with if statement?
2) Is it possible to use multiple default statements in swi tch () statement?
3) Write the use of else and default statements in i f . .e ls e and switch () statements respectively.
4) Why go to statement is avoided?
5) Why break statement is essential in swi tch () statement? Which other functions or keywords
can be used in place of the break statement.
6) Is it possible to use e ls e statement in place of default or vice versa?
7) Can we put default statement anywhere in the swi tc h () case structure?
8) What are the limitations of swi tch () case statement?
B) Answer the following by selecting the appropriate option.
1) The switch statement is used to
a) Switch between functions in a program.
b) switch from one variable to another variable.
c) choose from multiple possibilities which may arise due to different values of a single
variable.
d) use switching variables.
2) The default statement is executed when
a) all the case statements are false
b) one of the case is true
c) one of the case is false
d) none of the above
3) Each case statement in swi tch () is seperated by
a) break b) continue
4) The keyword else can be used with
a) i f statement
c) do..w hile() statement d)
5) What will be the output of the following program?
# include <stdio.h>
# include <conio.h>
void main ()
{
char x='H ';
c lr s c r ();
switch(x)
{
case 'H': printf("%c"/H');
c) e x it() d) goto
b) switch () statement
none of the above
Decision Statements 119
case 'E': printf("%c"/E');
case 'L': printf("%c"/L);
caseT: printf("%c"/L');
case'O: prin1f("%c"/0,);
}
a) HELLO b)
c) H d)
6) What will be the output of the following program?
void main()
I
char x='G';
switch(x)
{
if ( x=='B')
I
case'd': printf("%"/o');
case 'B': printf(,/%s","Bad");
else
case 'G': printf("%s","Good");
default: printf("%s"," Boy");
a) Good Boy b)
d) Boy d)
7) What will be the output of the following program?
# include <stdio.h>
# include <conio.h>
void mainO
{
char x='d' ;
clrscr();
switch(x)
{
case 'b':
puts( "01 001");
break;
default:
puts("l 2 3");
break;
case 'R':
puts("I II III");
)
)
a) 12 3 b)
c) m m d)
HELlo
none of the above
Bad Boy
none of the above
0 1 001
none of the above
120 Programming and Data Structures
C] Attempt the following programs.
1) Write a program to check whether the blood donor is eligible or not for donating blood. The
conditions laid down are as under. Use if statement.
a) Age should be above 18 years but not more than 55 years.
b) Weight should be more than 45 kg.
2) Write a program to check whether the voter is eligible for voting or not. If his/her age is equal to
or greater than 18, display message "Eligible" otherwise "Non- Eligible". Use if statement.
3) Write a program to calculate bill of a job work done as follows. Use if else statement.
a) Rate of typing 3 Rs./ page.
b) Printing of 1st copy 5 Rs. / pages & later every copy 3 Rs. /page.
The user should enter the number of pages and print out copies he/she wants.
4) Write a program to calculate the amount of the bill for the following jobs.
a) Scanning and hardcopy of a passport photo Rs. 5/-:
b) Scanning and hardcopies (more than 10) Rs. 3/-.
5) Write a program to calculate bill of Internet browsing. The conditions are given below.
a) 1 Hour -20 Rs.
b) Vi Hour -10 Rs.
c) Hours - 90 Rs.
The owner should enter number of hours spent by customer.
6) Write a program to enter a character through keyboard. Use switch () case structure and print
appropriate message. Recognize the entered character whether it is vowel, consonants, or symbol?
7) The table given below is a list of gases, liquids, and solids. By entering the substances one by one
through the keyboard, recognize their state (Gas, liquid and solid).
WATER OZONE
OXYGEN
PETROL
IRON ICE
GOLD
MERCURY
8) Write a program to calculate the sum of remainders obtained by dividing with modular division
operations by 2 on 1 to 9 numbers.

Get Programming and Data Structures now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.