C While Loop Examples
1. Printing Numbers from 1 to 10
Output:
2. Sum of First N Natural Numbers
Sample Input/Output:
3. Printing Even Numbers from 2 to 20
Output:
4. Factorial of a Number
Sample Input/Output:
5. Reading Numbers Until Zero is Entered
Sample Input/Output:
6. Multiplication Table of a Number
Sample Input/Output:
Key Points from Examples
-
whileloop is used when number of iterations is not fixed or depends on a condition. -
Always update loop variables to prevent infinite loops.
-
Can be used for counting, summing, input validation, and repetitive tasks.
