- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 Generate all the Divisors of an Integer
Steps
- Take the value of the integer and store it in a variable.
- Use a for loop and an if statement to generate the divisors of the integer.
- Print the divisors of the number.
Enter an integer:25 The divisors of the number are: 1 5 25 | The divisors of the number are: 20 1 2 4 5 10 20 |
Explanation
- User must first enter the value and store it in a variable.
- Use a for loop to generate numbers from 1 to n.
- Using an if statement, check if the number divided by i gives the remainder as 0 which is basically the divisor of the integer.
- Print the divisors of the number.
Example
package main import "fmt" func main(){ var n int fmt.Print("Enter an integer:") fmt.Scanf("%d", &n) fmt.Println("The divisors of the number are:") for i:=1; i<=n; i++{ if n%i==0 { fmt.Printf("%d\n", i) } } }
Output
Enter an integer:20 The divisors of the number are: 1 2 4 5 10 20
- Related Articles
- Golang Program to Find the Smallest Divisor of an Integer
- Golang Program To Get The Successor Of An Integer Number
- Golang Program to count the set bits in an integer.
- Golang Program to convert an integer into binary representation
- Golang Program To Get The Predecessor Of An Integer Number Using Library Function
- Check if the given array contains all the divisors of some integer in Python
- Golang Program To Remove All Occurrences Of An Element In An Array
- Golang program to remove all elements from an array
- How to Print an Integer in Golang?
- Golang program to create an integer array that takes inputs from users.
- Generate an integer sequence in MySQL?
- C++ Program to Perform Partition of an Integer in All Possible Ways
- Golang program to compute all the permutations of the string
- Find sum of divisors of all the divisors of a natural number in C++
- Golang program to calculate the sum of all even numbers

Advertisements