- Trending Categories
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 Check if a Number is a Perfect Number
Steps
- Read an integer and store it in a variable.
- Initialize a variable to count the sum of the proper divisors to 0.
- Use a for loop and an if statement to add the proper divisors of the integer to the sum variable.
- Check if the sum of the proper divisors of the number is equal to the variable.
- Print the final result.
Enter any number: 6 The number is a Perfect number! | Enter any number: 25 The number is not a Perfect number! |
Example
package main import "fmt" func main(){ var n int fmt.Print("Enter any number: ") fmt.Scanf("%d", &n) sum1 := 0 for i:=1; i<n;i++{ if n % i ==0{ sum1 += i } } if sum1 == n { print("The number is a Perfect number!") }else{ print("The number is not a Perfect number!") } }
Output
Enter any number: 6 The number is a Perfect number!
- Related Articles
- Python Program to Check if a Number is a Perfect Number
- Java Program to Check if a given Number is Perfect Number
- Swift Program to Check if the given number is Perfect number or not
- Check if the given number is a perfect cube: $216$.
- Python Program to Check if a Number is a Strong Number
- Swift Program to Check whether a number is a Perfect Cube or not
- C Program to check Plus Perfect Number
- Check if a number in a list is perfect square using Python
- Write a Golang program to check whether a given number is prime number or not
- 'Check if the following number is a perfect cube.10644'
- Golang Program to check a given number is finite or not
- To Check if a Number is a Munchhausen Number
- Python program to check if the given number is a Disarium Number
- Swift Program to Check If a Number is Spy number or not
- Golang program to check if k’th bit is set for a given number or not.

Advertisements