logo image

Go language program to print average of given 3 numbers

Views: 24

Following program shows you how to print average of given 3 numbers. In this program we get inputs from user and calculate average of given 3 numbers using following formula Average of given 3 numbers = (input1 + input2 + input3) / 3

package main

import "fmt"

func main() {

  var input1 int
  var input2 int
  var input3 int
  var result int
  fmt.Println("Enter first number:")
  fmt.Scanf("%d", &input1)
  fmt.Println("Enter second number:")
  fmt.Scanf("%d", &input2)
  fmt.Println("Enter third number:")
  fmt.Scanf("%d", &input3)
  result = (input1 + input2 + input3) / 3
  fmt.Println("The average of three numbers: " , result)


Enter first number:
Enter second number:
Enter third number:
The average of three numbers:  17