- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang program to create an integer array that takes inputs from users.
Example
Approach
Ask the user to enter the size of array.
Make an integer array of given size.
Ask the user to enter elements.
At the end, print the array.
Example
package main import ( "fmt" ) func main(){ fmt.Printf("Enter size of your array: ") var size int fmt.Scanln(&size) var arr = make([]int, size) for i:=0; i<size; i++ { fmt.Printf("Enter %dth element: ", i) fmt.Scanf("%d", &arr[i]) } fmt.Println("Your array is: ", arr) }
Output
Enter size of your array: 6 Enter 0th element: 10 Enter 1th element: 20 Enter 2th element: 30 Enter 3th element: 40 Enter 4th element: 50 Enter 5th element: 60 Your array is: [10 20 30 40 50 60]
Advertisements