
Practice 70 Go Lang Loops Coding Questions
Q1. Write a Go program to print numbers from 1 to 10 using a for loop.
Expected Output:
1 2 3 4 5 6 7 8 9 10
Q2. Write a Go program to print the first 10 even numbers using a for loop.
Expected Output:
2 4 6 8 10 12 14 16 18 20
Q3. Write a Go program to calculate the sum of numbers from 1 to 20 using a loop.
Expected Output:
Sum: 210
Q4. Write a Go program to print the multiplication table of 5 using a loop.
Expected Output:
5 x 1 = 5
5 x 2 = 10
...
5 x 10 = 50
Q5. Write a Go program to calculate the factorial of a number using a for loop.
Input:
5
Expected Output:
Factorial: 120
Q6. Write a Go program to display all odd numbers between 1 and 15.
Expected Output:
1 3 5 7 9 11 13 15
Q7. Write a Go program to find the sum of all even numbers between 1 and 50.
Expected Output:
Sum: 650
Q8. Write a Go program to reverse the digits of a number using a loop.
Input:
1234
Expected Output:
Reversed: 4321
Q9. Write a Go program to count the number of digits in a number using a loop.
Input:
56789
Expected Output:
Count of digits: 5
Q10. Write a Go program to print numbers from 10 to 1 in reverse order using a loop.
Expected Output:
10 9 8 7 6 5 4 3 2 1
Q11. Write a Go program to calculate the sum of the digits of a number using a loop.
Input:
1234
Expected Output:
Sum of digits: 10
Q12. Write a Go program to find the greatest common divisor (GCD) of two numbers using a loop.
Input:
12, 15
Expected Output:
GCD: 3
Q13. Write a Go program to check if a number is a palindrome using a loop.
Input:
121
Expected Output:
121 is a palindrome
Q14. Write a Go program to print the first n Fibonacci numbers using a loop.
Input:
7
Expected Output:
0 1 1 2 3 5 8
Q15. Write a Go program to calculate the power of a number using a loop.
Input:
Base: 2, Exponent: 5
Expected Output:
Result: 32
Q16. Write a Go program to print all prime numbers between 1 and 50.
Expected Output:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
Q17. Write a Go program to calculate the sum of the first 10 natural numbers.
Expected Output:
Sum: 55
Q18. Write a Go program to check if a number is prime using a loop.
Input:
17
Expected Output:
17 is a prime number
Q19. Write a Go program to find the smallest number in an array using a loop.
Input:
[3, 1, 4, 1, 5]
Expected Output:
Smallest number: 1
Q20. Write a Go program to count how many numbers in an array are greater than 10.
Input:
[5, 15, 10, 20, 25]
Expected Output:
Count: 3
Q21. Write a Go program to print all numbers divisible by 3 between 1 and 30.
Expected Output:
3 6 9 12 15 18 21 24 27 30
Q22. Write a Go program to calculate the product of all numbers in an array.
Input:
[2, 3, 4]
Expected Output:
Product: 24
Q23. Write a Go program to count the vowels in a string using a loop.
Input:
"hello world"
Expected Output:
Vowel count: 3
Q24. Write a Go program to print the sum of squares of the first 5 natural numbers.
Expected Output:
Sum of squares: 55
Q25. Write a Go program to find the largest number in an array using a loop.
Input:
[10, 5, 8, 12]
Expected Output:
Largest number: 12
Q36. Write a Go program to print the square of numbers from 1 to 10 using a for loop.
Expected Output:
1 4 9 16 25 36 49 64 81 100
Q37. Write a Go program to calculate the sum of all odd numbers between 1 and 30 using a loop.
Expected Output:
Sum: 225
Q38. Write a Go program to check if a number is divisible by both 3 and 5 using a loop.
Input:
15
Expected Output:
15 is divisible by both 3 and 5
Q39. Write a Go program to find the average of numbers from 1 to 100 using a loop.
Expected Output:
Average: 50.5
Q40. Write a Go program to calculate the Fibonacci series up to a certain number n using a loop.
Input:
5
Expected Output:
0 1 1 2 3
Q41. Write a Go program to print all numbers divisible by 4 between 1 and 50.
Expected Output:
4 8 12 16 20 24 28 32 36 40 44 48
Q42. Write a Go program to print the factorial of a number n using a loop.
Input:
6
Expected Output:
Factorial: 720
Q43. Write a Go program to print the elements of an array in reverse order.
Input:
[1, 2, 3, 4, 5]
Expected Output:
5 4 3 2 1
Q44. Write a Go program to calculate the sum of the elements of an array.
Input:
[2, 4, 6, 8]
Expected Output:
Sum: 20
Q45. Write a Go program to find the largest prime number less than 50 using a loop.
Expected Output:
Largest prime number less than 50: 47
Q46. Write a Go program to count how many times a specific number appears in an array.
Input:
Array: [1, 2, 2, 3, 2], Number: 2
Expected Output:
Count: 3
Q47. Write a Go program to print all numbers between 1 and 100 that are divisible by 5 but not 10.
Expected Output:
5 15 25 35 45 55 65 75 85 95
Q48. Write a Go program to display the sum of squares of numbers from 1 to n.
Input:
4
Expected Output:
Sum of squares: 30
Q49. Write a Go program to print a pattern of numbers as a triangle.
Input:
3
Expected Output:
1
2 3
4 5 6
Q50. Write a Go program to find the average of all numbers from 1 to 100 using a loop.
Expected Output:
Average: 50.5
Q51. Write a Go program to find the sum of the first n odd numbers using a loop.
Input:
5
Expected Output:
Sum: 25
Q52. Write a Go program to check if a number is divisible by 3, 5, or both using a loop.
Input:
30
Expected Output:
30 is divisible by both 3 and 5
Q53. Write a Go program to print the reverse of a string using a loop.
Input:
"hello"
Expected Output:
olleh
Q54. Write a Go program to print the Fibonacci series up to a number n.
Input:
21
Expected Output:
0 1 1 2 3 5 8 13 21
Q55. Write a Go program to find the sum of all the elements in a 2D array using loops.
Input:
[[1, 2], [3, 4], [5, 6]]
Expected Output:
Sum: 21
Q56. Write a Go program to print a triangle of stars using nested loops.
Input:
5
Expected Output:
*
**
***
****
*****
Q57. Write a Go program to print all prime numbers between m and n.
Input:
m: 10, n: 30
Expected Output:
11 13 17 19 23 29
Q58. Write a Go program to calculate the sum of squares of all numbers between 1 and n.
Input:
4
Expected Output:
Sum of squares: 30
Q59. Write a Go program to find the sum of even numbers between 1 and n.
Input:
10
Expected Output:
Sum: 30
Q60. Write a Go program to print the multiplication table for a given number n.
Input:
3
Expected Output:
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
...
Q61. Write a Go program to print all numbers that are divisible by 6 but not by 3 using a loop.
Expected Output:
6 12 18 24 30
Q62. Write a Go program to calculate the sum of the digits of a number using a loop.
Input:
5678
Expected Output:
Sum of digits: 26
Q63. Write a Go program to print all numbers divisible by 7 and 3 between 1 and 100.
Expected Output:
21 42 63 84
Q64. Write a Go program to find the second largest number in an array using a loop.
Input:
[4, 2, 8, 5, 6]
Expected Output:
Second largest number: 6
Q65. Write a Go program to find the number of vowels in a string using a loop.
Input:
"hello world"
Expected Output:
Vowel count: 3
Q66. Write a Go program to print all the elements in an array in reverse order using a loop.
Input:
[1, 2, 3, 4]
Expected Output:
4 3 2 1
Q67. Write a Go program to print numbers from 1 to n with a specific message if the number is divisible by 2 or 3.
Input:
10
Expected Output:
1
2 (divisible by 2)
3 (divisible by 3)
4 (divisible by 2)
...
Q68. Write a Go program to count how many numbers in an array are prime.
Input:
[2, 3, 4, 5, 6]
Expected Output:
Prime count: 3
Q69. Write a Go program to print the first n multiples of 10 using a loop.
Input:
5
Expected Output:
10 20 30 40 50
Q70. Write a Go program to check if a number is divisible by 2, 3, and 5.
Input:
30
Expected Output:
30 is divisible by 2, 3, and 5