30 programming questions based on the do-while loop in C


Q 1. Write a program to print numbers from 1 to 10 using a `do-while` loop.

Expected Output:

1 2 3 4 5 6 7 8 9 10

Q 2. Write a program to find the sum of numbers from 1 to 10 using a `do-while` loop.

Expected Output:

Sum = 55

Q 3. Write a program to print the following pattern using a `do-while` loop:

*
**
***
****
*****

Q 4. Write a program to reverse a given number using a `do-while` loop.

Expected Output:

Enter a number: 1234

Reversed number = 4321

Q 5. Write a program to calculate the factorial of a given number using a `do-while` loop.

Expected Output:

Enter a number: 5

Factorial = 120

Q 6. Write a program to print all even numbers between 1 and 20 using a `do-while` loop.

Expected Output:

2 4 6 8 10 12 14 16 18 20

Q 7. Write a program to find the sum of the digits of a given number using a `do-while` loop.

Expected Output:

Enter a number: 1234

Sum of digits = 10

Q 8. Write a program to check if a given number is a palindrome using a `do-while` loop.

Expected Output:

Enter a number: 1221

1221 is a palindrome

Q 9. Write a program to print all odd numbers between 1 and 20 using a `do-while` loop.

Expected Output:

1 3 5 7 9 11 13 15 17 19

Q 10. Write a program to find the largest digit in a given number using a `do-while` loop.

Expected Output:

Enter a number: 9472

Largest digit = 9

Q 11. Write a program to print the first 10 multiples of a given number using a `do-while` loop.

Expected Output:

Enter a number: 5

5 10 15 20 25 30 35 40 45 50

Q 12. Write a program to calculate the sum of squares of the first `n` natural numbers using a `do-while` loop.

Expected Output:

Enter a number: 3

Sum of squares = 14

Q 13. Write a program to print the Fibonacci series up to `n` terms using a `do-while` loop.

Expected Output:

Enter number of terms: 5

0 1 1 2 3

Q 14. Write a program to find the GCD of two numbers using a `do-while` loop.

Expected Output:

Enter two numbers: 54 24

GCD = 6

Q 15. Write a program to calculate the power of a given base number raised to an exponent using a `do-while` loop.

Expected Output:

Enter base and exponent: 2 3

Result = 8

Q 16. Write a program to find the sum of the first `n` odd numbers using a `do-while` loop.

Expected Output:

Enter a number: 5

Sum of first 5 odd numbers = 25

Q 17. Write a program to print the multiplication table of a given number using a `do-while` loop.

Expected Output:

Enter a number: 7

7 x 1 = 7

7 x 2 = 14

7 x 3 = 21

...

7 x 10 = 70

Q 18. Write a program to find the sum of all even digits in a given number using a `do-while` loop.

Expected Output:

Enter a number: 1234

Sum of even digits = 6

Q 19. Write a program to check if a given number is a perfect number using a `do-while` loop. (A perfect number is a number that is equal to the sum of its proper divisors.)

Expected Output:

Enter a number: 6

6 is a perfect number

Q 20. Write a program to convert a given decimal number to binary using a `do-while` loop.

Expected Output:

Enter a decimal number: 10

Binary = 1010

Q 21. Write a program to calculate compound interest using a `do-while` loop. The formula for compound interest is `A = P(1 + r/n)^(nt)`, where `P` is the principal amount, `r` is the annual interest rate, `n` is the number of times interest is compounded per year, and `t` is the number of years.

Expected Output:

Enter principal, rate, time, and number of times compounded: 1000 5 2 4

Compound Interest = 1104.94

Q 22. Write a program to print all prime numbers between 1 and 100 using a `do-while` loop.

Expected Output:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

Q 23. Write a program to calculate the product of the digits of a given number using a `do-while` loop.

Expected Output:

Enter a number: 123

Product of digits = 6

Q 24. Write a program to print all numbers divisible by 5 between 1 and 50 using a `do-while` loop.

Expected Output:

5 10 15 20 25 30 35 40 45 50

Q 25. Write a program to check if a given number is an Armstrong number using a `do-while` loop. (An Armstrong number is one that is equal to the sum of its own digits each raised to the power of the number of digits.)

Expected Output:

Enter a number: 153

153 is an Armstrong number

Q 26. Write a program to print all perfect squares between 1 and 100 using a `do-while` loop.

Expected Output:

1 4 9 16 25 36 49 64 81 100

Q 27. Write a program to find the sum of all prime numbers between 1 and 50 using a `do-while` loop.

Expected Output:

Sum of primes = 328

Q 28. Write a program to calculate the average of `n` numbers using a `do-while` loop.

Expected Output:

Enter the number of elements: 5

Enter number 1: 10

Enter number 2: 20

Enter number 3: 30

Enter number 4: 40

Enter number 5: 50

Average = 30

Q 29. Write a program to print numbers from 10 to 1 using a `do-while` loop.

Expected Output:

10 9 8 7 6 5 4 3 2 1

Q 30. Write a program to find the LCM of two numbers using a `do-while` loop.

Expected Output:

Enter two numbers: 12 15

LCM = 60

Social Share

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!