C Programming · Unit 4
Control Structures
Exam-focused notes for Control Structures (C Programming, BIT102): what the TU syllabus asks and how it has actually been tested, with 9 solved past questions from this unit.
What this unit covers
- If else statement
- If else ladder
- Nested if else
- Switch case statement
- Comparison of switch and if else ladder
- Break and continue statements
- Goto statement and labels
- Flowchart design
If else ladder
Explain if else ladder with syntax and semantic. Write a program to find largest among 3 different numbers. [2+3]
--- - The conditions are evaluated from top to bottom, one by one. - As soon as a condition evaluates to true, the corresponding block of statements is executed, and the rest of the ladder is skipped. - If none of the conditions is true, the final else bloc...
Full solved answer →Switch case statement
Explain different control structures in C. Write a program in C to perform different arithmetic operations on two integers and display the result based on choice made by user using switch statement.[10]
--- Control structures determine the flow of execution of a program. C provides three main categories: --- Statements are executed one after another in the order they appear. This is the default flow. --- Used to choose between alternative paths based on a ...
Full solved answer →Nested if else
Explain nested if else ladder with suitable example. [5]
A nested if-else ladder (also called if-else-if ladder) is a control structure where multiple conditions are checked in sequence. Each else branch contains another if condition, forming a chain (ladder) of conditions. The program checks each condition from ...
Full solved answer →Flowchart design
What do you mean by flowchart? Draw a Flowchart to find the largest among three numbers entered by user. [5]
A flowchart is a diagrammatic or pictorial representation of an algorithm or a step-by-step solution to a given problem. It uses standard geometric symbols connected by arrows (flow lines) to show the sequence of steps, decisions, and operations required to...
Full solved answer →Write an algorithm and flowchart to test whether the given integer is odd or even. [5]
--- Problem: Given an integer N, determine whether it is odd or even. Step 1: START Step 2: Read the integer N Step 3: Check if N MOD 2 = 0 (i.e., divide N by 2 and check the remainder) Step 4: If the remainder is 0, then print "N is Even" Step 5: Else prin...
Full solved answer →Break and continue statements
How break statement is different from continue statement. Explain with examples? [5]
The break statement is used to immediately terminate the loop (or switch) in which it appears. When break is executed, the program control jumps to the first statement after the loop. Output: The loop stops completely when i == 5. --- The continue statement...
Full solved answer →How break statement is different from continue statement? Explain with suitable example. [5]
Feature break continue --------- Purpose Terminates the entire loop immediately Skips only the current iteration Control flow Exits the loop body completely Goes back to the loop condition check Remaining iterations All remaining iterations are skipped Rema...
Full solved answer →Comparison of switch and if else ladder
Differentiate between switch statement and if else if ladder. [5]
A series of if, else if, and else blocks used to test multiple conditions sequentially. Syntax: --- A multi-way branching statement that tests a variable against a list of constant values (cases). Syntax: --- Feature Switch Statement If-Else-If Ladder -----...
Full solved answer →Differentiate between switch case and else .. if ladder. Why is break statement used inside switch case? Explain briefly. [5]
Feature Switch Case Else-If Ladder --------- Basis of comparison Tests a single variable/expression against multiple constant values Tests multiple different conditions (expressions) Data type Works with integer, character, and enumeration types only Works ...
Full solved answer →Make Unit 4 stick
Practice BIT102 with flashcards & quizzes