Genarate series of odd number (do... while loop)

0
Output

Explanation of the Odd Number do-while Loop Program

This program prints all odd numbers starting from 1 up to a user-defined limit. It uses a do-while loop, which ensures that the loop body runs at least once before checking the condition.

The program begins with the first odd number (1) and increments by 2 each time. This continues until the value becomes greater than the last number entered by the user.

What the Program Does

  • Starts with the first odd number (fno = 1).
  • Asks the user to enter the last number (lno).
  • Uses a do-while loop to print numbers like 1, 3, 5, 7, etc.
  • Increments by 2 to ensure only odd numbers are printed.
  • Stops when the next odd number exceeds the last number.
  • Uses getch() to pause the screen (Turbo C feature).

Example Input

Enter the last number: 15

Example Output

1 3 5 7 9 11 13 15

Summary: This program prints a sequence of odd numbers by repeatedly adding 2, using a do-while loop. It is a simple demonstration of loop control, number sequences, and Turbo C input/output functions.

Tags

Post a Comment

0Comments

Post a Comment (0)