Computer Science 10th Unit 3 Conditional Logic

Welcome to the fascinating world of Unit #3 in 10th class computer science: CONDITIONAL LOGIC. In this unit, students will delve into the realm of control and selection statements, gaining a profound understanding of how computers make decisions. By the end of this unit, learners will have the skills to define and differentiate control and selection statements, comprehend the structure of ‘if’ and ‘if-else’ statements, and even master the art of creating nested selection structures. This knowledge will empower students to write code that can adapt and respond intelligently to various scenarios, marking a pivotal step forward in their journey to becoming proficient computer scientists.

10th Computer Unit 3 Long Questions Notes

10th Computer Unit 3 MCQ’s

10th Computer Unit 3 Activities Notes

10th Computer Unit 3 Exercise

10th Computer Unit 3 Short Questions Notes

Question: What is conditional logic?
Answer: Conditional logic refers to the process of making decisions in programming based on certain conditions. It involves executing specific tasks or code blocks if a given condition is true and potentially executing different tasks if the condition is false.

Question: What are control statements in programming?
Answer: Control statements in programming are used to manage the flow of execution within a program. They allow us to determine which set of instructions to execute based on specific conditions or loops.

Question: Name the three types of control statements in C language.
Answer: The three types of control statements in C language are:

Sequential Control Statements
Selection Control Statements
Repetition Control Statements

Question: What is the focus of the discussed chapter in relation to control statements?
Answer: The focus of the discussed chapter is on the selection control statements.

Question: What are selection statements in programming?
Answer: Selection statements are used to decide which statements or code blocks should be executed next, based on specific conditions.

Question: What is the structure of an if statement in C language?
Answer: The structure of an if statement in C language is as follows:
if (condition)
Associated Code

Question: Give an example of a valid condition for an if statement.
Answer: Example of valid conditions:

5 > 4
a == b
!(x < y)

Question: What happens if the condition inside an if statement is false?
Answer: If the condition inside an if statement is false, the associated code block will not be executed.

Question: When do you need to use curly braces {} with an if statement?
Answer: Curly braces {} are used when you want to associate more than one statement with an if statement. If you have only one statement, using curly braces is optional but recommended for clarity.

Provide an example where an if statement includes multiple statements within curly braces.

Answer: Example:
if (value > 10) {
printf(“Value is greater than 10.\n”);
printf(“This is a positive value.\n”);
}

Question: What is the formula for calculating Gross Salary in the given program?
ANSWER: Gross Salary = Basic Salary + (Number of Items Sold * 8) + Bonus

Question: When is the bonus assigned in the program?
ANSWER: The bonus is assigned if the number of items sold is more than 100 and there are no broken items. In that case, the bonus is Rs. 10,000; otherwise, the bonus remains 0.

QUESTION: Why is the gross salary calculated outside the ‘if’ block in the program?
ANSWER: The gross salary needs to be calculated regardless of whether the bonus is given or not, based on the number of items sold. So, it is calculated outside the ‘if’ block.

QUESTION: What is the purpose of using the ‘if-else’ statement in programming?
ANSWER: The ‘if-else’ statement allows executing one set of instructions when a condition is true and another set of instructions when the condition is false.

QUESTION: In the ‘if-else’ statement, what code is executed when the condition is false?
ANSWER: The code associated with the ‘else’ statement is executed when the condition in the ‘if’ statement is false.

QUESTION: Is it necessary for an ‘if’ statement to have an associated ‘else’ statement?
ANSWER: No, an ‘if’ statement can exist without an associated ‘else’ statement, but an ‘else’ statement must be associated with an ‘if’ statement.

QUESTION: How should multiple statements be enclosed under an ‘if’ statement before the ‘else’ keyword?
ANSWER: Multiple statements under an ‘if’ statement should be enclosed within curly braces {} before the ‘else’ keyword.

QUESTION: What is a compound statement or block in programming?
ANSWER: A compound statement or block is a set of multiple instructions enclosed within curly braces {}.

QUESTION: Provide an example scenario where the ‘if-else’ statement is used.
ANSWER: If the age of a person is between 13 and 19, the program displays “Teenager”; otherwise, it doesn’t.

QUESTION: How can you determine whether a given year is a leap year or not?
ANSWER: A year is a leap year if it is divisible by 4.

QUESTION: Why is proper indentation important in programming?
ANSWER: Proper indentation enhances the readability of the code and helps programmers understand the program’s structure.

QUESTION: What does the ‘&&’ operator represent in the context of conditional statements?
ANSWER: The ‘&&’ operator represents the logical AND operator, which checks whether both conditions on its sides are true.

QUESTION: What is the purpose of the ‘scanf’ function in C programming?
ANSWER: The ‘scanf’ function is used to read input from the user during runtime.

QUESTION: How does the program in the example determine whether a character entered is a digit or not?
ANSWER: The program checks whether the entered character is within the ASCII range of ‘0’ to ‘9’ using comparison operators.

QUESTION: How does the program determine whether a person has a fever or not based on body temperature?
ANSWER: If the body temperature is more than 98.6, the program displays “You have fever”; otherwise, it displays “You don’t have fever.”

QUESTION: Why should instructions under an ‘if’ statement or ‘else’ statement be enclosed in a block?
ANSWER: Instructions under ‘if’ or ‘else’ statements need to be enclosed in a block to ensure that the compiler treats them as a single unit. Otherwise, only the first instruction is considered, and subsequent instructions are treated independently.

QUESTION: What is the structure of an if-else-if statement in C language?
ANSWER: The structure of an if-else-if statement in C language is as follows:
if (condition1)
Code to execute if condition1 is true;
else if (condition2)
Code to execute if condition1 is false but condition2 is true;
else if (conditionN)
Code to execute if all previous conditions are false but conditionN is true;
else
Code to execute if all the conditions are false;

QUESTION: How can you determine a student’s grade based on their percentage marks in C language?
ANSWER: To determine a student’s grade based on percentage marks, you can use the provided program logic:
if (percentage >= 80)
printf(“A\n”);
else if (percentage >= 70)
printf(“B\n”);
else if (percentage >= 60)
printf(“C\n”);
else if (percentage >= 50)
printf(“D\n”);
else
printf(“F\n”);

QUESTION:What are nested selection structures in programming?
ANSWER: Nested selection structures refer to the concept of having conditional statements (if statements or if-else statements) within other conditional statements. It means that inside an ‘if’ block or an ‘else’ block, there can be more ‘if’ statements or ‘if-else’ statements, and this nesting can continue further.

Leave a Comment