All Subjects Free PDF Educational Books, Notes, Past Papers Etc. Website:, E-Mail
All Subjects Free PDF Educational Books, Notes, Past Papers Etc. Website:, E-Mail
Program:
When this program is executed, it reads an integer number, stores it in the
variable n and then the condition (n>0) is evaluated.
If it is true, it prints the message that the entered number is a positive number
and then the nested if-else statement is exe uted.
The nested if-else statement prints whether n is an even number or an odd
number.
If the condition (n>0) is false then the statements following the first if are skipped
and the last statement after the else is executed which prints the message that the
user entered a negative number r zero.
Ans: Count = 10
Sum = 58
============================================================
Visit www.easymcqs.com for Notes, Old Papers, PDF, IT Courses & more (Page 3 of 7)
Download All Subjects Free PDF Educational Books, Notes, Past Papers etc.
Website: www.easymcqs.com , E-mail: [email protected]
TH
COMPUTER SCIENCE FOR 10 CLASS (UNIT # 4)
============================================================
LONG QUESTION
Use of If Statement:
Program 1: The program in Fig, demonstrates the use of if statement.
============================================================
Visit www.easymcqs.com for Notes, Old Papers, PDF, IT Courses & more (Page 4 of 7)
Download All Subjects Free PDF Educational Books, Notes, Past Papers etc.
Website: www.easymcqs.com , E-mail: [email protected]
TH
COMPUTER SCIENCE FOR 10 CLASS (UNIT # 4)
============================================================
Structure Of If-Else Statement:
The if-else statement is used in situation hwre some code is to be executed if a
condition is true and some other code is to be executed if the condition is false. The
if-else statement has the following general form.
if (condition)
{
Block of statements
}
else
{
Block of statements
}
When if-else statement is executed. The condition is evalua d.
If the condition is true then the block of statements f ll wing if will be executed
and the block of statements following else will be skipped.
If the condition is false then the block of stateme ts following if will be skipped and
the block of statements following else will be executed.
If a single statement is to be executed after if or else then braces are not
required.
============================================================
Visit www.easymcqs.com for Notes, Old Papers, PDF, IT Courses & more (Page 5 of 7)
Download All Subjects Free PDF Educational Books, Notes, Past Papers etc.
Website: www.easymcqs.com , E-mail: [email protected]
TH
COMPUTER SCIENCE FOR 10 CLASS (UNIT # 4)
============================================================
When this statement is executed, contion-1 is evaluated, if it is true then the block
of statements following if is executed and if it is false, the next condition is
evaluated.
If any condition is true then the following block of statements is executed.
If none of the conditions is true then the block of statements following else is
executed automatically.
If a single statement is to be executed after if, else-if or else, instead f set of
statement then the braces are not required.
Switch Statement:
The switch statement has the following general form.
Switch (expression)
{
Case const-1;
Statement;
Break;
Case conts-2;
Statements;
Break;
.
.
.
Default:
Statements;
}
The switch statement is simi ar to the else-if statement. It is used when multiple
choices are given and o e ch ice is to be selected.
When this pr gram is executed, the switch variable must have an integer value.
The value of switch variable n is compared with the constant values statements
following that particular case.
If the s itch variable does not match any of the case constants, control goes the
key ord default which is at the end of the switch statement.
Notice the use of break statement in this program. It terminates the switch
statement when the body of the statements in a particular case has been
executed.
============================================================
Visit www.easymcqs.com for Notes, Old Papers, PDF, IT Courses & more (Page 7 of 7)