๐ For Loop Based Programs
๐ For Loop Based Programs
-
Print all even numbers from 1 to N.
๐ก Hint: Start from 2, increment pointer by 2 until it reaches or exceeds N. -
Reverse a string using a for loop.
๐ก Hint: Use one pointer from end to start, append characters to result. -
Find the sum of the first N natural numbers.
๐ก Hint: One pointer moves from 1 to N, accumulate total. -
Print a right-angled triangle of stars with N rows.
๐ก Hint: Outer pointer for rows, inner pointer for stars in each row. -
Find all prime numbers up to N.
๐ก Hint: Outer loop for numbers, inner loop checks divisibility up to √N.
๐ While Loop Based Programs
-
Count the number of digits in an integer.
๐ก Hint: Use one pointer to divide number by 10 until it becomes 0. -
Check if a number is a palindrome.
๐ก Hint: Use two pointers—start and end digit comparision via math. -
Print the Fibonacci sequence up to N terms.
๐ก Hint: Two pointers hold last two values, loop until term count reached. -
Find the factorial of a number.
๐ก Hint: Use a pointer starting from 1, multiply until reaching the number. -
Check if an array is sorted in ascending order.
๐ก Hint: Use two pointers—current and next index to compare elements.
Comments
Post a Comment