5 Loops And Iteration

C Programming · Unit 5

Loops and Iteration

Exam-focused notes for Loops and Iteration (C Programming, BIT102): what the TU syllabus asks and how it has actually been tested, with 6 solved past questions from this unit.

What this unit covers

  • For loop structure and syntax
  • While loop
  • Do while loop
  • Comparison of while and do while
  • Nested loops
  • Loop control statements
  • Odd loops

Loop control statements

208110 marks

What is loop? Differentiate between break and continue statement.Write a program to find sum of first N natural numbers.[6+4]

--- A loop is a control structure that allows repeated execution of a block of statements as long as a given condition remains true. Loops are used to avoid writing the same code multiple times. Loop Type Description ------------------------ for loop Used w...

Full solved answer →
20815 marks

Write a program to check whether a given number is Armstrong number or not. [5]

An Armstrong number (also called a narcissistic number) is a number that equals the sum of its own digits each raised to the power of the number of digits. Example: - 153 = 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 ✓ - 371 = 3³ + 7³ + 1³ = 27 + 343 + 1 = 371 ✓ --- ...

Full solved answer →
05 marks

Define iterative statements. Write a program that using a loop to compute and prints the sum of squares of first 10 even natural numbers. [5]

Iterative statements (also called loop statements or repetition statements) are control flow statements that allow a block of code to be executed repeatedly based on a condition. They continue executing the loop body until the specified condition becomes fa...

Full solved answer →

For loop structure and syntax

20805 marks

Explain structure of for loop. Write a program to reverse a number entered by user. [5]

The for loop is an entry-controlled loop used when the number of iterations is known in advance. Syntax: Explanation of each part: Part Description ------------------- Initialization Sets the starting value of the loop variable (executed once) Condition Che...

Full solved answer →

Comparison of while and do while

207910 marks

When do we use for loop and while loop? Compare the while and do while loop with suitable example.Write a program to find average, minimum and maximum age in a class of 20 students.[4+6]

--- Use a for loop when: - The number of iterations is known in advance - You have a clear initialization, condition, and increment/decrement - Iterating over arrays, ranges, or fixed counts Example: Use a while loop when: - The number of iterations is not ...

Full solved answer →

Odd loops

2081.210 marks

Define odd loop. What do you mean by goto and label? Write a program to generate the following pattern.

1
2 2
3 3 3
4 4 4 4

[10]

--- An odd loop is a loop in which the number of iterations is not known in advance at compile time. The loop continues or terminates based on a condition that is evaluated at runtime, often depending on user input or some external event. Key Characteristic...

Full solved answer →