Top 30 programming questions on For loop in C Programming


Q 1. Write a program to print numbers from 1 to 10 using a `for` loop.

Expected Output:

1 2 3 4 5 6 7 8 9 10

Q 2. Write a program to print the sum of the first 10 natural numbers using a `for` loop.

Expected Output:

Sum = 55

Q 3. Write a program to print the multiplication table of a given number using a `for` loop.

Expected Output:

Enter a number: 5

5 x 1 = 5

5 x 2 = 10

...

5 x 10 = 50

Q 4. Write a program to calculate the factorial of a given number using a `for` loop.

Expected Output:

Enter a number: 5

Factorial = 120

Q 5. Write a program to print the first `n` even numbers using a `for` loop.

Expected Output:

Enter a number: 5

2 4 6 8 10

Q 6. Write a program to find the sum of the digits of a given number using a `for` loop.

Expected Output:

Enter a number: 1234

Sum of digits = 10

Q 7. Write a program to print all odd numbers between 1 and 50 using a `for` loop.

Expected Output:

1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49

Q 8. Write a program to reverse a given number using a `for` loop.

Expected Output:

Enter a number: 1694

Reversed number = 4961

Q 9. Write a program to check if a given number is prime using a `for` loop.

Expected Output:

Enter a number: 29

29 is a prime number

Q 10. Write a program to calculate the sum of squares of the first `n` natural numbers using a `for` loop.

Expected Output:

Enter a number: 3

Sum of squares = 14

Q 11. Write a program to print the first `n` Fibonacci numbers using a `for` loop.

Expected Output:

Enter number of terms: 5

0 1 1 2 3

Q 12. Write a program to calculate the sum of the series `1 + 1/2 + 1/3 + ... + 1/n` using a `for` loop.

Expected Output:

Enter a number: 5

Sum = 2.28333

Q 13. Write a program to find the greatest common divisor (GCD) of two numbers using a `for` loop.

Expected Output:

Enter two numbers: 36 60

GCD = 12

Q 14. Write a program to check if a given number is a palindrome using a `for` loop.

Expected Output:

Enter a number: 121

121 is a palindrome

Q 15. Write a program to print all prime numbers between 1 and 100 using a `for` 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 16. Write a program to find the sum of all even numbers between 1 and 100 using a `for` loop.

Expected Output:

Sum = 2550

Q 17. Write a program to print all numbers divisible by both 3 and 5 between 1 and 100 using a `for` loop.

Expected Output:

15 30 45 60 75 90

Q 18. Write a program to print the reverse of a given string using a `for` loop.

Expected Output:

Enter a string: Hello

Reversed string: olleH

Q 19. Write a program to calculate the sum of the digits of all prime numbers between 1 and 50 using a `for` loop.

Expected Output:

Sum of digits of primes = 30

Q 20. Write a program to print the following pattern using a `for` loop:

*
**
***
****
*****
Q 21. Write a program to calculate the product of the digits of a given number using a `for` loop.

Expected Output:

Enter a number: 123

Product of digits = 6

Q 22. Write a program to print all factors of a given number using a `for` loop.

Expected Output:

Enter a number: 20

Factors: 1 2 4 5 10 20

Q 23. Write a program to calculate the sum of the first `n` odd numbers using a `for` loop.

Expected Output:

Enter a number: 5

Sum = 25

Q 24. Write a program to print all perfect squares between 1 and 100 using a `for` loop.

Expected Output:

1 4 9 16 25 36 49 64 81  100

Q 25. Write a program to check if a given number is an Armstrong number using a `for` loop.

Expected Output:

Enter a number: 153

153 is an Armstrong number

Q 26. Write a program to find the LCM of two numbers using a `for` loop.

Expected Output:

Enter two numbers: 12 18

LCM = 36

Q 27. Write a program to print the ASCII values of characters from `a` to `z` using a `for` loop.

Expected Output:

a = 97

b = 98

...

z = 122

Q 28. Write a program to calculate the sum of all prime numbers between 1 and 100 using a `for` loop.

Expected Output:

Sum = 1060

Q 29. Write a program to print the first `n` terms of the series `1, 4, 9, 16, ...` using a `for` loop.

Expected Output:

Enter a number: 5

1 4 9 16 25

Q 30. Write a program to print the sum of the squares of the digits of a given number using a `for` loop.

Expected Output:

Enter a number: 123

Sum of squares of digits = 14

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!