Skip to main content

ads1

class 10 Chapter :- 13 Decision Structures


 Decision Structures

Decision structure statements help us to jump from one part of the program to another part of program based on result of some conditions. Sometimes decision structure statements are also known as selective structures statements, branching statements or decision making statements.

C language provides two basic types of decision structure statements: if and switch.

The if Statement

The if statement is one of the powerful decision making statement which can be used to transfer control of instruction execution. The if statement can be used in following different ways:

Simple if statement

if-else statement

nested if statement and

else-if ladder statement

Simple if statement :-

The simplest form of the decision structure statement is the if statement. It is frequently used in the program for decision making and allowing us to change the flow of program execution

Nested if...else statement

There are situations where we need to execute series of decisions in our program. We may use series of if..else statement in nested form to achieve our task. Consider the following case where one if..else statement block is used inside another if..else block.
if (test expression-1)
{
if(test expression-2)
{
Statement block-1;
else
Statement block-2;

The else-if ladder statement

There is another way of using many if statements together when we want to evaluate multiple decisions. When chain of if statements are used in else (false) block of nested if statements, it becomes else if ladder statement.

The Switch Statement

We have used the if...else statement for selection of various statement blocks during program execution.  The program becomes difficult to read and interpret the logic. To simplify our program, the C language has offered the built-in facility of multiway decision statement called switch.

Syntax of the Switch Statement
switch (expression)
case value-1:
statement block-1
break; case value-2:
statement block-2 break;
...
case value-n:
statement block-n
break; default:
default statement block break;
statement-x;

Choose the correct option from the following:

(1) What is the value of variable flag after the execution of following if statement ?
int flag=0;
if(5 <8) { flag=1; }

(a) O
(b) 1
(c) 5
(d) 8

(2) What is the value of variable 's' after the execution of following switch statement ?
X = 3;
switch ( x ) {
case 1: s = 'A'; break;
case 2: s = 'B'; break;
case 3: s = 'C'; break;
default: s = 'D'; break;
(a) A
(b) B
(c) C
(d) D


(3) What is the value of variable sum after the execution of following statements ?
int number1=5, number2=10, sum=0;
if (number1 > number2)
sum = sum + numberl;
else
sum = sum + number2;

(a) O
(b) 5
(c) 10
(d) 12
 
(4) What will be the output when following program segment is executed ?
int numberl=10, number2=20; if ((number1+number2) > 35 || (number1 > number2))
printf("%d", numberl);
else
printf("%d", number2);

(a) 10
(b) 20
(c) 35
(d) Error

(5) What will be the output when following program segment is executed ?
char chr='A';
switch (chr)
case 'A': printf("A"); break; case 'B': printf("B"); break; case 'C': printf("C"); break;
 

(a) A
(b) B
(c) C
(d) Error


















ads2

Popular posts from this blog

11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following:

    11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following: Basic Salary <= 10000 : HRA = 20%, DA = 80% Basic Salary <= 20000 : HRA = 25%, DA = 90% Basic Salary > 20000 : HRA = 30%, DA = 95% Static Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     if(basic <=10000)     {         da = basic * 0.8;         hra = basic *0.2;     }              else if(basic <=20000)     {         da = basic * 0.9;         hra = basic *0.25;     }     else     {         da = basic * 0.95;         hra = basic * 0.3;     }     gross = basic + da + hra;     System.out.println("The Gross Salary is :-"+gross);     } } Output :-  Dynamic Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     Scanner in = new Scanner(System.in);     System.out.println("Enter the Basic Salary

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise or class wise.

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise  or class wise. Solution :-   # x-axis is shows the subject and y -axis # shows the markers in each subject # import pandas and matplotlib  import pandas as pd  import matplotlib.pyplot as plt # Simple Line Chart with setting of Label of X and Y axis, # title for chart line and color of line  subject = ['Physic','Chemistry','Mathematics', 'Biology','Computer'] marks =[80,75,70,78,82] # To draw line in red colour plt.plot(subject,marks,'r',marker ='*')     # To Write Title of the Line Chart plt.title('Marks Scored') # To Put Label At Y Axis plt.xlabel('SUBJECT')           # To Put Label At X Axis plt.ylabel('MARKS')             plt.show() Output :- 

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category.

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category. import pandas as pd  # initialize list of lists data = [['CAR','Maruti',1000000],['AC','Hitachi',55000],['AIRCOLLER','Bajaj',12000], ['WASHING MACHINE','LG',15000],['CAR','Ford',7000000],['AC','SAMSUNG',45000],['AIRCOLLER','Symphony',20000],['WASHING MACHINE','Wirlpool',25000]] Col=['itemcat','itemname','expenditure'] # Create the pandas DataFrame qrtsales = pd.DataFrame(data,columns=Col) # print dataframe.  print (qrtsales) qs=qrtsales.groupby('itemcat')  print('Result after Filtering Dataframe')  print(qs['itemcat','expenditure'].sum()) Output :-