11. Create a Go program to count the frequency of words in a string using a map.

Required Input:

A string (e.g., "Go is fun and Go is fast").

Expected Output:

Word Frequencies: map[Go:2 is:2 fun:1 and:1 fast:1]

Code In Go

package main import "fmt" func main() { // Count word frequencies in a string }

Run Code?

Click Run Button to view compiled output

12. Create a Go program to generate Fibonacci numbers up to a given limit using a loop.

Required Input:

An integer n = 10.

Expected Output:

[0 1 1 2 3 5 8 13 21 34]

Code In Go

package main import "fmt" func fibonacci(n int) []int { // Generate Fibonacci numbers up to the limit return nil } func main() { fmt.Println(fibonacci(10)) }

Run Code?

Click Run Button to view compiled output

13. Write a Go program to demonstrate the use of time.Ticker to execute a task periodically.

Required Input:

A ticker interval of 1 second.

Expected Output:

Task executed
Task executed
Task executed
Task executed
Task executed

Code In Go

package main import "fmt" func main() { // Use time.Ticker to execute a task periodically }

Run Code?

Click Run Button to view compiled output

14. Write a Go program to marshal a struct into JSON and save it to a file.

Required Input:

A struct Person{Name: "Alice", Age: 25}.

Expected Output:

JSON data saved to output.json

Code In Go

package main import "fmt" func main() { // Marshal a struct into JSON and save it to a file }

Run Code?

Click Run Button to view compiled output

15. Create a Go program to implement a circular queue using a slice.

Required Input:

Operations: enqueue 10, 20, dequeue, enqueue 30, dequeue.

Expected Output:

30 

Code In Go

package main import "fmt" type CircularQueue struct { // Define fields for the queue } func main() { // Implement enqueue and dequeue operations }

Run Code?

Click Run Button to view compiled output

16. Write a Go program to demonstrate the use of a custom struct as a key in a map.

Required Input:

Struct Point with fields X and Y.

Expected Output:

Point A
Point B

Code In Go

package main import "fmt" type Point struct { // Define fields for the struct } func main() { // Use the struct as a map key }

Run Code?

Click Run Button to view compiled output

17. Create a Go program to implement a simple publish-subscribe model using channels.

Required Input:

Subscribers listen for messages on a channel.

Expected Output:

Subscriber 2 received: Hello
Subscriber 2 received: World
Subscriber 2 received: From
Subscriber 2 received: Publisher

Code In Go

package main import "fmt" func publisher(ch chan string) { // Send messages to the channel } func subscriber(ch chan string, id int) { // Receive and print messages from the channel } func main() { // Set up publisher and subscribers }

Run Code?

Click Run Button to view compiled output

18. Write a Go program to implement a simple calculator using interfaces for different operations.

Required Input:

Two integers (e.g., 10, 5) and operations (+, -, *, /).

Expected Output:

15
5
50
2

Code In Go

package main import "fmt" type Operation interface { Compute(a, b int) int } func main() { // Implement different operations using the interface }

Run Code?

Click Run Button to view compiled output

19. Create a Go program to merge two sorted slices into one sorted slice.

Required Input:

Two sorted slices (e.g., [1, 3, 5] and [2, 4, 6]).

Expected Output:

[1 2 3 4 5 6]

Code In Go

package main import "fmt" func mergeSlices(slice1, slice2 []int) []int { // Implement the merging logic return nil } func main() { // Merge two sorted slices and print the result }

Run Code?

Click Run Button to view compiled output

20. Create a Go program to implement a worker pool pattern using goroutines and channels.

Required Input:

A set of tasks (e.g., [1, 2, 3, 4, 5]).

Expected Output:

Worker 3 processing task 1
Worker 3 processing task 3
Worker 3 processing task 4
Worker 3 processing task 5
Result: 2
Result: 6
Result: 8
Result: 10
Worker 1 processing task 2
Result: 4

Code In Go

package main import "fmt" func worker(id int, tasks <-chan int, results chan<- int) { // Implement worker functionality } func main() { // Set up workers and task processing }

Run Code?

Click Run Button to view compiled output

ad vertical

2 of 3