Practice 100 Go Lang Basics Coding Questions, TechnoVlogs

Practice 100 Go Lang Basics Coding Questions


Q1. Write a Go program to print "Hello, World!".  
  Input: None  
  Expected Output:  
  Hello, World!

Q2. Write a Go program to calculate the sum of two integers provided by the user.  
  Input:    
  5
  10
  Expected Output:  
  Sum: 15

Q3. Write a Go program to check whether a number is even or odd.  
  Input:    
  7
  Expected Output:  
  7 is odd

Q4. Write a Go program to find the largest of three numbers.  
  Input:    
  12
  7
  15
  Expected Output:  
  Largest number: 15

Q5. Write a Go program to reverse a string entered by the user.  
  Input:    
  golang
  Expected Output:  
  Reversed string: gnalog

Q6. Write a Go program to check whether a given year is a leap year.  
  Input:    
  2024
  Expected Output: 
  2024 is a leap year

Q7. Write a Go program to print the first 10 natural numbers.  
  Input: None  
  Expected Output:    
  1 2 3 4 5 6 7 8 9 10

Q8. Write a Go program to calculate the factorial of a number.  
  Input:    
  5
  Expected Output:  
  Factorial of 5 is 120

Q9. Write a Go program to check if a string is a palindrome.  
  Input:    
  radar
  Expected Output:  
  radar is a palindrome

Q10. Write a Go program to print the Fibonacci series up to n terms.  
   Input:     
   7
   Expected Output:  
   Fibonacci series: 0 1 1 2 3 5 8

Q11. Write a Go program to find the square of a number.  
   Input:     
   4
   Expected Output: 
   Square: 16

Q12. Write a Go program to swap two numbers using a temporary variable.  
   Input:     
   3 7
   Expected Output: 
   Before swapping: a = 3, b = 7  
   After swapping: a = 7, b = 3

Q13. Write a Go program to check if a character is a vowel or consonant.  
   Input:     
   a
   Expected Output:  
   a is a vowel

Q14. Write a Go program to calculate the area of a circle given the radius.  
   Input:     
   7
   Expected Output:  
   Area: 153.93804

Q15. Write a Go program to find the smallest of three numbers.  
   Input:     
   15 10 25
   Expected Output:  
   Smallest number: 10

Q16. Write a Go program to check if a number is positive, negative, or zero.  
   Input:     
   -8
   Expected Output:  
   -8 is a negative number

Q17. Write a Go program to calculate the power of a number using a loop.  
   Input:     
   3 4
   Expected Output: 
   3^4 = 81

Q18. Write a Go program to calculate the sum of digits of a number.  
   Input:     
   1234
   Expected Output:  
   Sum of digits: 10

Q19. Write a Go program to print a multiplication table for a given number.  
   Input:     
   5
   Expected Output: 
   5 x 1 = 5  
   5 x 2 = 10  
   ...  
   5 x 10 = 50

Q20. Write a Go program to count the number of vowels in a string.  
   Input:     
   golang
   Expected Output:  
   Number of vowels: 2

Q21. Write a Go program to find the greatest common divisor (GCD) of two numbers.  
   Input:     
   56 98
   Expected Output:  
   GCD: 14

Q22. Write a Go program to print the ASCII value of a character.  
   Input:     
   A
   Expected Output:  
   ASCII value of A: 65

Q23. Write a Go program to print the reverse of a number.  
   Input:     
   12345
   Expected Output:  
   Reversed number: 54321

Q24. Write a Go program to print all even numbers from 1 to n.  
   Input:     
   10
   Expected Output: 
   2 4 6 8 10

Q25. Write a Go program to check if a number is a perfect square.  
   Input:     
   16
   Expected Output:  
   16 is a perfect square

Q26. Write a Go program to find the second largest number in an array.  
   Input:     
   [12, 35, 1, 10, 34, 1]
   Expected Output:  
   Second largest number: 34

Q27. Write a Go program to check if a string contains only digits.  
   Input:     
   12345
   Expected Output:  
   The string contains only digits

Q28. Write a Go program to calculate the length of a string.  
   Input:     
   Hello
   Expected Output:  
   Length of string: 5

Q29. Write a Go program to merge two arrays into one.  
   Input:     
   Array1: [1, 2, 3]  
   Array2: [4, 5, 6]
   Expected Output:  
   Merged array: [1, 2, 3, 4, 5, 6]

Q30. Write a Go program to count the frequency of each character in a string.  
   Input:     
   hello
   Expected Output:  
   h: 1  
   e: 1  
   l: 2  
   o: 1

Q31. Write a Go program to remove all vowels from a string.  
   Input:     
   golang
   Expected Output:  
   String without vowels: glng

Q32. Write a Go program to check if a number is prime.  
   Input:     
   29
   Expected Output:  
   29 is a prime number

Q33. Write a Go program to find the sum of elements in an array.  
   Input:     
   [1, 2, 3, 4, 5]
   Expected Output:  
   Sum: 15

Q34. Write a Go program to calculate the average of numbers in an array.  
   Input:     
   [10, 20, 30, 40, 50]
   Expected Output:  
   Average: 30

Q35. Write a Go program to find the maximum element in an array.  
   Input:     
   [15, 42, 7, 89, 23]
   Expected Output:  
   Maximum element: 89

Q36. Write a Go program to sort an array in ascending order.  
   Input:     
   [12, 4, 8, 1, 19]
   Expected Output:  
   Sorted array: [1, 4, 8, 12, 19]

Q37. Write a Go program to count the number of words in a string.  
   Input:     
   Hello World from Go
   Expected Output:  
   Word count: 4

Q38. Write a Go program to print the first n prime numbers.  
   Input:     
   5
   Expected Output:  
   First 5 prime numbers: 2 3 5 7 11

Q39. Write a Go program to convert Celsius to Fahrenheit.  
   Input:     
   25
   Expected Output:  
   Fahrenheit: 77

Q40. Write a Go program to convert Fahrenheit to Celsius.  
   Input:     
   98.6
   Expected Output:  
   Celsius: 37

Q41. Write a Go program to find the LCM of two numbers.  
   Input:     
   15 20
   Expected Output: 
   LCM: 60

Q42. Write a Go program to print all prime numbers up to n.  
   Input:     
   20
   Expected Output: 
   Prime numbers: 2 3 5 7 11 13 17 19

Q43. Write a Go program to find the nth Fibonacci number.  
   Input:     
   6
   Expected Output: 
   6th Fibonacci number: 8

Q44. Write a Go program to check if two strings are anagrams.  
   Input:     
   listen silent
   Expected Output:  
   The strings are anagrams

Q45. Write a Go program to remove duplicate elements from an array.  
   Input:     
   [1, 2, 2, 3, 4, 4, 5]
   Expected Output: 
   Array without duplicates: [1, 2, 3, 4, 5]

Q46. Write a Go program to generate a random number between 1 and 100.  
   Input: None  
   Expected Output:     
   Random number: (varies)

Q47. Write a Go program to print the current date and time.  
   Input: None  
   Expected Output:     
   Current date and time: (varies)

Q48. Write a Go program to calculate the sum of even numbers in an array.  
   Input:     
   [1, 2, 3, 4, 5]
   Expected Output:  
   Sum of even numbers: 6

Q49. Write a Go program to convert a string to uppercase.  
   Input:     
   golang
   Expected Output:  
   Uppercase: GOLANG

Q50. Write a Go program to convert a string to lowercase.  
   Input:     
   GoLang
   Expected Output:  
   Lowercase: golang

Q51. Write a Go program to find the sum of odd numbers in an array.  
   Input:     
   [1, 2, 3, 4, 5]
   Expected Output: 
   Sum of odd numbers: 9

Q52. Write a Go program to check if a string is empty or not.  
   Input:     
   ""
   Expected Output:  
   The string is empty

Q53. Write a Go program to find the product of all elements in an array.  
   Input:     
   [1, 2, 3, 4]
   Expected Output:  
   Product: 24

Q54. Write a Go program to print the first n multiples of a number.  
   Input:     
   Number: 3  
   n: 5
   Expected Output:  
   Multiples of 3: 3 6 9 12 15

Q55. Write a Go program to print the ASCII values of all characters in a string.  
   Input:     
   Hello
   Expected Output:  
   H: 72  
   e: 101  
   l: 108  
   l: 108  
   o: 111

Q56. Write a Go program to calculate the sum of the first n natural numbers.  
   Input:     
   10
   Expected Output:  
   Sum: 55

Q57. Write a Go program to check if an array is sorted in ascending order.  
   Input:     
   [1, 2, 3, 4, 5]
   Expected Output:  
   Array is sorted in ascending order

Q58. Write a Go program to count the number of positive and negative numbers in an array.  
   Input:     
   [-3, 5, -1, 2, -4]
   Expected Output: 
   Positive numbers: 2  
   Negative numbers: 3

Q59. Write a Go program to print all elements at even indices in an array.  
   Input:     
   [10, 20, 30, 40, 50]
   Expected Output:  
   Elements at even indices: 10 30 50

Q60. Write a Go program to print the multiplication table of a number using recursion.  
   Input:     
   3  
   5
   Expected Output:  
   3 x 1 = 3  
   3 x 2 = 6  
   3 x 3 = 9  
   3 x 4 = 12  
   3 x 5 = 15

Q61. Write a Go program to print a right-angled triangle pattern of stars.  
   Input:     
   4
   Expected Output:  
   *  
   **  
   ***  
   ****

Q62. Write a Go program to calculate the total number of digits in a number.  
   Input:     
   12345
   Expected Output:  
   Total digits: 5

Q63. Write a Go program to check if a number is divisible by both 3 and 5.  
   Input:     
   15
   Expected Output:  
   15 is divisible by both 3 and 5

Q64. Write a Go program to reverse an array.  
   Input:     
   [1, 2, 3, 4, 5]
   Expected Output: 
   Reversed array: [5, 4, 3, 2, 1]

Q65. Write a Go program to count the occurrences of a given element in an array.  
   Input:     
   Array: [1, 2, 2, 3, 4, 2]  
   Element: 2
   Expected Output:  
   Occurrences of 2: 3

Q66. Write a Go program to find the average of even numbers in an array.  
   Input:     
   [1, 2, 3, 4, 5, 6]
   Expected Output:  
   Average of even numbers: 4

Q67. Write a Go program to find the sum of elements at odd indices in an array.  
   Input:     
   [10, 20, 30, 40, 50]
   Expected Output:  
   Sum of elements at odd indices: 60

Q68. Write a Go program to calculate the power of a number using recursion.  
   Input:     
   Base: 2  
   Exponent: 3
   Expected Output:  
   2^3 = 8

Q69. Write a Go program to check if an element exists in an array.  
   Input:     
   Array: [1, 2, 3, 4, 5]  
   Element: 4
   Expected Output: 
   4 exists in the array

Q70. Write a Go program to print a rectangle pattern using stars.  
   Input:     
   Rows: 3  
   Columns: 4
   Expected Output:  
   ****  
   ****  
   ****

Q71. Write a Go program to calculate the factorial of a number using recursion.  
   Input:     
   5
   Expected Output:  
   Factorial of 5: 120

Q72. Write a Go program to check if two arrays are equal.  
   Input:     
   Array1: [1, 2, 3]  
   Array2: [1, 2, 3]
   Expected Output:  
   The arrays are equal

Q73. Write a Go program to print all odd numbers from 1 to n.  
   Input:     
   10
   Expected Output:  
   1 3 5 7 9

Q74. Write a Go program to find the median of an array.  
   Input:     
   [1, 3, 2, 4, 5]
   Expected Output:  
   Median: 3

Q75. Write a Go program to find the first occurrence of an element in an array.  
   Input:     
   Array: [10, 20, 30, 20, 40]  
   Element: 20
   Expected Output:  
   First occurrence of 20 is at index 1

Q76. Write a Go program to print the transpose of a 2x2 matrix.  
   Input:     
   [[1, 2], [3, 4]]
   Expected Output:  
   Transposed matrix:  
   [1, 3]  
   [2, 4]

Q77. Write a Go program to find the mode of an array (most frequently occurring element).  
   Input:     
   [1, 2, 2, 3, 4, 4, 4, 5]
   Expected Output:  
   Mode: 4

Q78. Write a Go program to check if a number is an Armstrong number.  
   Input:     
   153
   Expected Output:  
   153 is an Armstrong number

Q79. Write a Go program to count the number of digits in an integer.  
   Input:     
   987654
   Expected Output: 
   Number of digits: 6

Q80. Write a Go program to find the sum of the main diagonal elements of a 3x3 matrix.  
   Input:     
   [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
   Expected Output:  
   Sum of diagonal elements: 15

Q81. Write a Go program to check if a number is a palindrome.  
   Input:     
   121
   Expected Output:  
   121 is a palindrome

Q82. Write a Go program to calculate the greatest difference between two elements in an array.  
   Input:     
   [3, 10, 6, 2, 15]
   Expected Output:  
   Greatest difference: 13

Q83. Write a Go program to rotate an array by one position to the left.  
   Input:     
   [1, 2, 3, 4, 5]
   Expected Output:  
   Rotated array: [2, 3, 4, 5, 1]

Q84. Write a Go program to rotate an array by one position to the right.  
   Input:     
   [1, 2, 3, 4, 5]
   Expected Output: 
   Rotated array: [5, 1, 2, 3, 4]

Q85. Write a Go program to count the occurrences of each number in an array.  
   Input:     
   [1, 2, 2, 3, 3, 3]
   Expected Output:  
   1: 1  
   2: 2  
   3: 3

Q86. Write a Go program to calculate the average of an array excluding the largest and smallest values.  
   Input:     
   [10, 20, 30, 40, 50]
   Expected Output:  
   Average (excluding 10 and 50): 30

Q87. Write a Go program to print the factors of a number.  
   Input:     
   12
   Expected Output:  
   Factors: 1 2 3 4 6 12

Q88. Write a Go program to print the Pascal's triangle up to n rows.  
   Input:     
   5
   Expected Output: 
   1  
   1 1  
   1 2 1  
   1 3 3 1  
   1 4 6 4 1

Q89. Write a Go program to check if two strings are rotations of each other.  
   Input:     
   String1: abcde  
   String2: deabc
   Expected Output:  
   The strings are rotations of each other

Q90. Write a Go program to find the minimum and maximum element in an array.  
   Input:     
   [12, 4, 56, 8, 19]
   Expected Output:     
   Minimum: 4  
   Maximum: 56

Q91. Write a Go program to find the first n odd numbers.  
   Input:     
   5
   Expected Output:  
   1 3 5 7 9

Q92. Write a Go program to remove an element from an array at a specified index.  
   Input:     
   Array: [10, 20, 30, 40, 50]  
   Index: 2
   Expected Output:  
   Array after removal: [10, 20, 40, 50]

Q93. Write a Go program to print all prime factors of a number.  
   Input:     
   60
   Expected Output: 
   Prime factors: 2 2 3 5

Q94. Write a Go program to check if a string starts with a specified prefix.  
   Input:     
   String: golang  
   Prefix: go
   Expected Output:  
   The string starts with "go"

Q95. Write a Go program to find the sum of elements at even indices in an array.  
   Input:     
   [10, 20, 30, 40, 50]
   Expected Output:  
   Sum of elements at even indices: 90

Q96. Write a Go program to find the greatest of two numbers using a function.  
   Input:     
   12  
   7
   Expected Output:  
   Greatest number: 12

Q97. Write a Go program to print the reverse of a string using recursion.  
   Input:     
   golang
   Expected Output:  
   Reversed string: gnalog

Q98. Write a Go program to implement linear search on an array.  
   Input:     
   Array: [10, 20, 30, 40, 50]  
   Element: 30
   Expected Output:  
   Element found at index 2

Q99. Write a Go program to implement binary search on a sorted array.  
   Input:     
   Array: [10, 20, 30, 40, 50]  
   Element: 40
   Expected Output:  
   Element found at index 3

Q100. Write a Go program to calculate the power of a number using a loop.  
   Input:     
   Base: 2  
   Exponent: 5
   Expected Output:  
   2^5 = 32

Share on Social Media