- 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 check if two numbers are Amicable Numbers
Steps
- Read two integers and store them in separate variables.
- Find the sum of the proper divisors of both the numbers.
- Check if the sum of the proper divisors is equal to the opposite numbers.
- If they are equal, they are amicable numbers.
- Print the final result.
Enter number 1: 220 Enter number 2: 284 Amicable! | Enter number 1: 349 Enter number 2: 234 Not Amicable! |
Example
package main import "fmt" func main(){ var a, b int fmt.Print("Enter first number: ") fmt.Scanf("%d", &a) fmt.Print("Enter second number: ") fmt.Scanf("%d", &b) sum1 := 0 for i:=1; i<a; i++{ if a%i==0{ sum1+=i } } sum2 := 0 for i:=1; i<b; i++{ if b%i==0{ sum2+=i } } if sum1==b && sum2==a{ fmt.Println("Amicable!") } else{ fmt.Println("Not Amicable!") } }
Output
Enter first number: 220 Enter second number: 284 Amicable!
- Related Articles
- Python Program to Check If Two Numbers are Amicable Numbers
- How to check if two numbers (m,n) are amicable or not using Python?
- Golang Program to Check if two Strings are Anagram
- Python program to check if binary representation of two numbers are anagram.
- Java program to check if binary representations of two numbers are anagram
- C++ Program to check if given numbers are coprime or not
- How to Add Two Numbers in Golang?
- How to Swap Two Numbers in Golang?
- Check if binary representations of two numbers are anagram in Python
- Golang Program to Read Two Numbers and Print their Quotient and Remainder
- Golang Program to Display Prime Numbers Between Two Intervals using library functions.
- How to add two Complex numbers in Golang?
- Check if sum of divisors of two numbers are same in Python
- Golang Program to Print Spiral Pattern of Numbers
- Write a Golang program to swap two numbers without using a third variable

Advertisements