Practice 50 Go Lang Packages and Modules Coding Questions, TechnoVlogs

Practice 50 Go Lang Packages and Modules Coding Questions


Q1. Write a Go program to create a simple package that adds two numbers.  
  Input:    
  Numbers: 3, 5
  Expected Output:  
  Sum: 8

Q2. Write a Go program to import a package and use its function to multiply two numbers.  
  Input:    
  Numbers: 6, 7
  Expected Output:  
  Product: 42

Q3. Write a Go program to create a package with a function that returns the square of a number.  
  Input:    
  Number: 4
  Expected Output:  
  Square: 16

Q4. Write a Go program that uses a custom package to calculate the factorial of a number.  
  Input:    
  Number: 5
  Expected Output:  
  Factorial: 120

Q5. Write a Go program to create a module and use it in the main program to calculate the area of a circle.  
  Input:    
  Radius: 3
  Expected Output:  
  Area: 28.27433

Q6. Write a Go program that imports a package and uses its function to find the maximum of two numbers.  
  Input:    
  Numbers: 8, 5
  Expected Output:  
  Maximum: 8

Q7. Write a Go program to create a package that calculates the power of a number.  
  Input:    
  Base: 2, Exponent: 3
  Expected Output:  
  Power: 8

Q8. Write a Go program that imports a package and uses it to find the length of a string.  
  Input:    
  String: "GoLang"
  Expected Output:  
  Length: 6

Q9. Write a Go program to use a package that concatenates two strings.  
  Input:    
  String 1: "Go", String 2: "Lang"
  Expected Output:  
  Concatenated string: GoLang

Q10. Write a Go program to create a module that finds the average of an array of integers.  
   Input:     
   Array: [1, 2, 3, 4, 5]
   Expected Output:  
   Average: 3

Q11. Write a Go program to create a package that checks if a number is prime.  
   Input:     
   Number: 7
   Expected Output:  
   Prime: true

Q12. Write a Go program that imports a custom package and checks whether a string is a palindrome.  
   Input:     
   String: "radar"
   Expected Output:  
   Palindrome: true

Q13. Write a Go program to import and use a package to generate a random number between 1 and 100.  
   Input:     
   Range: 1 to 100
   Expected Output:  
   Random number: (example: 42)

Q14. Write a Go program to create a module that calculates the perimeter of a rectangle.  
   Input:     
   Length: 5, Width: 3
   Expected Output:  
   Perimeter: 16

Q15. Write a Go program to import a package that reverses a string.  
   Input:     
   String: "Hello"
   Expected Output:  
   Reversed string: olleH

Q16. Write a Go program to create a module for converting temperature from Celsius to Fahrenheit.  
   Input:     
   Celsius: 25
   Expected Output:  
   Fahrenheit: 77

Q17. Write a Go program to import a package that checks if a number is even or odd.  
   Input:     
   Number: 10
   Expected Output:  
   Even: true

Q18. Write a Go program to create a package that returns the Fibonacci sequence up to a given number.  
   Input:     
   Number: 10
   Expected Output:  
   Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8

Q19. Write a Go program to create a module that finds the largest element in a slice.  
   Input:     
   Slice: [1, 5, 3, 9, 2]
   Expected Output:  
   Largest element: 9

Q20. Write a Go program to import a package and format the date into a specific pattern.  
   Input:     
   Date: 2025-01-14
   Format: January 14, 2025
   Expected Output:  
   Formatted date: January 14, 2025

Q21. Write a Go program to create a package for converting a string to uppercase.  
   Input:     
   String: "golang"
   Expected Output:  
   Uppercase: GOLANG

Q22. Write a Go program to import a package that calculates the length of an array.  
   Input:     
   Array: [10, 20, 30, 40]
   Expected Output:  
   Length: 4

Q23. Write a Go program to create a module that returns the remainder of a division.  
   Input:     
   Dividend: 10, Divisor: 3
   Expected Output:  
   Remainder: 1

Q24. Write a Go program to import a package and calculate the sum of all elements in an array.  
   Input:     
   Array: [1, 2, 3, 4, 5]
   Expected Output:  
   Sum: 15

Q25. Write a Go program to create a package that converts a string to a number (int).  
   Input:     
   String: "100"
   Expected Output:  
   Number: 100

Q26. Write a Go program that imports a package to find the GCD of two numbers.  
   Input:     
   Numbers: 24, 36
   Expected Output:  
   GCD: 12

Q27. Write a Go program that imports a package to find the LCM of two numbers.  
   Input:     
   Numbers: 5, 10
   Expected Output:  
   LCM: 10

Q28. Write a Go program to create a module that calculates the area of a triangle.  
   Input:     
   Base: 5, Height: 3
   Expected Output:  
   Area: 7.5

Q29. Write a Go program to create a package for calculating the difference between two numbers.  
   Input:     
   Number 1: 15, Number 2: 5
   Expected Output:  
   Difference: 10

Q30. Write a Go program that imports a package and converts an integer to a string.  
   Input:     
   Integer: 42
   Expected Output:  
   String: "42"

Q31. Write a Go program to create a module that returns the cube of a number.  
   Input:     
   Number: 3
   Expected Output:  
   Cube: 27

Q32. Write a Go program that imports a package to find the sum of squares of numbers in an array.  
   Input:     
   Array: [1, 2, 3]
   Expected Output: 
   Sum of squares: 14

Q33. Write a Go program to create a package that finds the first N prime numbers.  
   Input:     
   N: 5
   Expected Output:  
   First 5 primes: 2, 3, 5, 7, 11

Q34. Write a Go program that imports a package to format a string in camel case.  
   Input:     
   String: "hello world from go"
   Expected Output:  
   Camel case: helloWorldFromGo

Q35. Write a Go program to create a package that calculates the harmonic mean of two numbers.  
   Input:     
   Numbers: 4, 6
   Expected Output:  
   Harmonic Mean: 4.8

Q36. Write a Go program to import a package and check if a string is a valid email address.  
   Input:     
   String: "test@example.com"
   Expected Output:  
   Valid email: true

Q37. Write a Go program to create a module that performs matrix addition.  
   Input:     
   Matrix 1: [[1, 2], [3, 4]]
   Matrix 2: [[5, 6], [7, 8]]
   Expected Output:  
   Sum of matrices: [[6, 8], [10, 12]]

Q38. Write a Go program to create a package that checks if a year is a leap year.  
   Input:     
   Year: 2024
   Expected Output:  
   Leap year: true

Q39. Write a Go program that imports a package and calculates the area of a circle.  
   Input:  
   Radius: 4
   Expected Output:  
   Area: 50.2654

Q40. Write a Go program to create a package for finding the median of an array.  
   Input:     
   Array: [1, 3, 2, 4]
   Expected Output:  
   Median: 2.5

Q41. Write a Go program to create a module that checks whether a string contains another string.  
   Input:     
   String 1: "GoLang is awesome"
   String 2: "awesome"
   Expected Output:  
   Contains: true

Q42. Write a Go program that imports a package to find the smallest element in a slice.  
   Input:     
   Slice: [3, 5, 1, 9]
   Expected Output:  
   Smallest element: 1

Q43. Write a Go program to create a module that calculates the BMI of a person.  
   Input:     
   Weight: 70, Height: 1.75
   Expected Output:  
   BMI: 22.86

Q44. Write a Go program to import a package that calculates the standard deviation of a set of numbers.  
   Input:     
   Numbers: [1, 2, 3, 4, 5]
   Expected Output:  
   Standard deviation: 1.414

Q45. Write a Go program to create a module for multiplying matrices.  
   Input:     
   Matrix 1: [[1, 2], [3, 4]]
   Matrix 2: [[5, 6], [7, 8]]
   Expected Output:  
   Product of matrices: [[19, 22], [43, 50]]

Q46. Write a Go program to create a package for checking if a number is a perfect number.  
   Input:     
   Number: 6
   Expected Output:  
   Perfect number: true

Q47. Write a Go program to import a package that capitalizes the first letter of each word in a string.  
   Input:     
   String: "hello world"
   Expected Output:  
   Capitalized string: Hello World

Q48. Write a Go program to create a module that concatenates two strings with a separator.  
   Input:     
   String 1: "Hello", String 2: "Go"
   Separator: "-"
   Expected Output:  
   Concatenated string: Hello-Go

Q49. Write a Go program that imports a package to sort an array of numbers.  
   Input:     
   Array: [9, 5, 3, 7]
   Expected Output:  
   Sorted array: [3, 5, 7, 9]

Q50. Write a Go program to create a module for checking if a number is an Armstrong number.  
   Input:     
   Number: 153
   Expected Output:  
   Armstrong number: true

Share on Social Media