 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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
Advertisements
 