Create a Go program to implement a producer-consumer problem using channels.
MediumProblem Statement
Create a Go program to implement a producer-consumer problem using channels.
Sample Input
A producer sends tasks (e.g., Task 1, Task 2), and a consumer processes them.
Sample Output
Produced: Task 1 Consumed: Task 1 Consumed: Task 2 Produced: Task 2 Produced: Task 3 Consumed: Task 3
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
package main
import "fmt"
func producer(ch chan string) {
// Send tasks to the channel
}
func consumer(ch chan string) {
// Process tasks from the channel
}
func main() {
// Set up producer and consumer
}
Input
A producer sends tasks (e.g., Task 1, Task 2), and a consumer processes them.
Expected Output
Produced: Task 1 Consumed: Task 1 Consumed: Task 2 Produced: Task 2 Produced: Task 3 Consumed: Task 3