Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6955011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:40:54+00:00 2026-05-27T14:40:54+00:00

I try to write a small application in go that takes ‘x’ numbers of

  • 0

I try to write a small application in go that takes ‘x’ numbers of integers from standard input, calculates the mean and gives it back. I have only gotten so far:

func main() {
var elems, mean int
sum := 0

fmt.Print("Number of elements? ")

fmt.Scan(&elems)

var array = new([elems]int)

for i := 0; i < elems; i++ {
    fmt.Printf("%d . Number? ", i+1)
    fmt.Scan(&array[i])
    sum += array[i];
}............

When trying to compile this I get the following error message:

invalid array bound elems

What is wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:40:55+00:00Added an answer on May 27, 2026 at 2:40 pm

    You should use a slice instead of an array:

    //var array = new([elems]int) - no, arrays are not dynamic
    var slice = make([]int,elems) // or slice := make([]int, elems)
    

    See "go slices usage and internals". Also you may want to consider using range for your loop:

    // for i := 0; i < elems; i++ { - correct but less idiomatic
    for i, v := range slice {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to write a simple client/server application (all application is a bluetooth service
I try to write a macro in clojure that sets up a namespace and
I'm working on unit-tests for an application which has a constructor that takes three
I was writing a console application that would try to guess a number by
I am attempted to write a small asynchronous socket library that I can use
Currently i have an application that reads and writes several properties from one or
I have a small application that I wrote that imports both the iTunes and
I'd like to write a small Bluetooth server application to my Nokia phone in
Iam suffering from Zend_validate ,when ever I write a form and try to add
I'm trying to build a small inventory application in Java, that switches views (or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.