Unit 3: Control Statements and Decision Making - Subjective Questions

CAP1008 — C Programming • Practice Questions with Detailed Answers

20 questions

1

What are control statements in C? Explain the need for control statements in a program.

2

Explain the simple if statement in C with its syntax, flowchart description, and an example.

3

Explain the if-else statement with syntax and a program to check whether a number is even or odd.

4

What is a nested if statement? Write a program using nested if to find the largest of three numbers.

5

Explain the else-if ladder with syntax and write a program to assign grades based on marks.

6

Explain the switch statement in C in detail with its syntax, rules, and an example.

7

Distinguish between the if-else ladder and the switch statement.

8

What is a loop? Explain the three essential elements of any loop and classify the loops available in C.

9

Explain the while loop with syntax, working, and a program to print the sum of first natural numbers.

10

Explain the do-while loop and write a program to display a menu that repeats until the user chooses to exit.

11

Compare the while loop and the do-while loop with a suitable example of each.

12

Explain the for loop in detail with syntax, working, and a program to print a multiplication table.

13

What is a nested loop? Write a program to print the following pattern using nested for loops:

*

  • *
    • *

14

Explain the break statement and the continue statement in C with examples. How do they differ?

15

Explain the goto statement in C with its syntax and an example. Why is its use generally discouraged?

16

Write a C program to check whether a given number is prime or not, and explain the logic used.

17

Describe the concept of an infinite loop. How can it be created intentionally and unintentionally? Give examples of each.

18

Write a C program using a loop to reverse a given integer number and check whether it is a palindrome.

19

Explain the different forms of the if statement in C (simple if, if-else, nested if, else-if ladder) with a brief description of when to use each.

20

What is meant by the fall-through behavior in a switch statement? Explain with an example and describe how it can be both a problem and a useful feature.