/GoExercises

Easy programming exercises for Go beginners.

Primary LanguageGo

GoExercises

Easy programming exercises for Go beginners.

1. Favourite numbers

Task

Write a function "add" that returns a sum of two integers.
Get two random integers from range 0-100 and print the sum of them.

Example output

My favorite number is: 84
My least favorite number is: 23
Their sum equals: 107

2. User input

Task

Ask the user for his name and his age.
Print his answers in one line.

Example output

Whats your name? >> Jan
How old are you? >> 18
Hello, Jan. You are 18 years old.

3. Fibonacci numbers

Task

Write a function that calculates Fibonacci number/sequence.
Ask the user how many Fibonacci numbers he wants to have printed.
Print Fibonacci sequence as long as user requested.

Example output

How many Fibonacci numbers you want to print? >> 10
0 1 1 2 3 5 8 13 21 34

4. Switch-case menu

Task

Create a simple menu that continuously (in loop) asks a user for a choice.
It should have following options:
Choice "1" - Print current date
Choice "2" - Print current time
Choice "3" - Print current weather information based on current hour or year season (doesn't have to be exact;)
Choice "4" - Exit the program

Example output

Welcome to Go Menu Choice!
Choose 1 to get current date
Choose 2 to get current time
Choose 3 to get current weather
Choose 4 to exit
Choice >> 2
Current time is: 4:58PM

5. Minimum in container

Task

Generate an array/slice of 20 random values from range 0-100. Print it.
Then search for the minimum value in this container and print it.

Example output

[85 75 75 52 56 8 56 5 44 58 73 29 40 5 37 25 38 97 71 8]
Minimum: 5

6. Estimate Pi with Monte-Carlo

Task

Implement the estimation of PI value with the use of Monte-Carlo method.
The number of samples used in the calculation should be passed as command line argument.

Example output

$ 06_pi_monte_carlo.exe 10000
Estimate Pi with 10000 samples.
Result: 3.1432