Questions on Loops
Questions on Loops
For Loop
1. Write a program to print the first 10 natural numbers using a for loop.
2. Modify the above program to print only the odd numbers from 1 to 20.
3. Write a program to calculate the factorial of a number using a for loop.
While Loop
4. Write a program to print the multiplication table of a given number using a
while loop.
5. Write a program to find the sum of digits of a number using a while loop.
Do-While Loop
6. Write a program to input numbers from the user and calculate their sum.
Stop taking input when the user enters a negative number.
7. Write a program to print numbers from 1 to 10 using a do-while loop.