Here are five programming interview questions related to loops:




Here are five programming interview questions related to loops:

1. **FizzBuzz with a Twist:**
   - Write a program that prints the numbers from 1 to N.
   - For multiples of 3, print "Fizz" instead of the number.
   - For multiples of 5, print "Buzz" instead of the number.
   - For numbers which are multiples of both 3 and 5, print "FizzBuzz".
   - Now, modify the program to replace any number containing the digit 3 with "Fizz" and any number containing the digit 5 with "Buzz".

2. **Reverse a String:**
   - Implement a function to reverse a given string without using any built-in reverse functions.
   - Optimize the solution to handle both iterative and recursive approaches.

3. **Sum of Digits:**
   - Write a program to find the sum of digits of a given positive integer.
   - Repeat the process until a single-digit result is obtained.

4. **Factorial Calculation:**
   - Implement a function to calculate the factorial of a non-negative integer using a loop.
   - Optimize the solution to handle both iterative and recursive approaches.

5. **Print a Pattern:**
   - Write a program to print the following pattern for a given integer N:
     ```
     1
     22
     333
     4444
     ...
     NNN...N
     ```
   - Implement the solution using nested loops.

These questions cover various aspects of loops, including basic control flow, string manipulation, digit manipulation, and pattern printing. They can help assess a candidate's understanding of loop constructs and problem-solving skills.


Contact us for software training, education or development










 

Post a Comment

0 Comments

Me