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

0
Output

Explanation of the Number Printing do-while Loop Program

This program prints a sequence of numbers starting from 1 up to a user-defined limit. It uses a do-while loop, which ensures the printing happens at least once before checking the condition.

The program begins by setting the first number to 1 and then repeatedly increments it by 1, printing each value until it becomes greater than the last number entered by the user.

What the Program Does

  • Starts with the first number (fno = 1).
  • Asks the user to enter the last number (lno).
  • Uses a do-while loop to print numbers from 1 onward.
  • Increments the number by 1 after each print.
  • Stops when the number becomes greater than the last number.
  • Uses getch() to pause the screen (Turbo C feature).

Example Input

Enter the last number: 5

Example Output

1 2 3 4 5

Summary: This program prints numbers from 1 to the number entered by the user. It demonstrates the working of a do-while loop, where the loop executes at least once before checking the condition.

Tags

Post a Comment

0Comments

Post a Comment (0)