C++ FOR, WHILE & Nested Loops - 50 Problem
Sheet
Beginner (1-10)
1. Print numbers from 1 to N.
2. Print numbers from N to 1.
3. Print even numbers from 1 to N.
4. Print odd numbers from 1 to N.
5. Sum of first N natural numbers.
6. Factorial of a number.
7. Multiplication table of a number.
8. Count numbers from 1 to N without directly using N.
9. Reverse counting using while.
10. Sum of even numbers from 1 to N.
Intermediate (11-30)
11. Sum of odd numbers.
12. Count digits.
13. Reverse a number.
14. Palindrome check.
15. Largest digit.
16. Smallest digit.
17. Sum of digits.
18. Product of digits.
19. Armstrong number.
20. Strong number.
21. Prime check.
22. Print primes 1..N.
23. Count primes 1..N.
24. First N primes.
25. Sum of primes 1..N.
26. Solid square pattern.
27. Right triangle pattern.
28. Inverted triangle pattern.
29. Increasing number triangle.
30. Repeated number triangle.
Advanced (31-50)
31. Reverse number triangle.
32. Alphabet triangle.
33. Reverse alphabet triangle.
34. Right-aligned inverted star triangle.
35. Right-aligned star triangle.
36. Full pyramid.
37. Inverted pyramid.
38. Diamond pattern.
39. Hollow square.
40. Hollow triangle.
41. GCD using loops.
42. LCM using loops.
43. Fibonacci series.
44. Check Fibonacci number.
45. Floyd's triangle.
46. Pascal's triangle (without arrays).
47. Butterfly pattern.
48. Hollow diamond.
49. Spiral square pattern.
50. Design your own symmetric pattern using at least 3 nested loops, spaces, numbers
and stars; explain the logic.
Bonus: Solve each problem using both for and while where possible, dry-run before
execution, and analyze time complexity.