Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
C program to verify if the numbers are abundant(friendly) or not?
In C programming, abundant numbers (also called friendly numbers) are special numbers where the sum of their proper divisors equals the number itself. Two numbers form an abundant pair if both numbers are abundant individually.
Syntax
// Find sum of proper divisors
for(i = 1; i < number; i++) {
if(number % i == 0) {
sum = sum + i;
}
}
// Check if abundant
if(sum == number) {
// Number is abundant
}
Example: Checking Abundant Pairs
The following program checks if two given numbers form an abundant pair −
#include <stdio.h>
int main() {
int number1, number2, i;
int result1 = 0, result2 = 0;
printf("Enter two numbers: ");
scanf("%d %d", &number1, &number2);
// Find sum of proper divisors of number1
for(i = 1; i < number1; i++) {
if(number1 % i == 0) {
result1 = result1 + i;
}
}
// Find sum of proper divisors of number2
for(i = 1; i < number2; i++) {
if(number2 % i == 0) {
result2 = result2 + i;
}
}
// Check if both numbers are abundant
if(result1 == number1 && result2 == number2) {
printf("Abundant Pairs<br>");
} else {
printf("Not abundant Pairs<br>");
}
return 0;
}
Enter two numbers: 6 28 Abundant Pairs
How It Works
- Number 6: Proper divisors are 1, 2, 3. Sum = 1 + 2 + 3 = 6 (abundant)
- Number 28: Proper divisors are 1, 2, 4, 7, 14. Sum = 1 + 2 + 4 + 7 + 14 = 28 (abundant)
- Since both numbers are abundant, they form an abundant pair
Key Points
- Proper divisors are all divisors except the number itself
- A number is abundant if the sum of its proper divisors equals the number
- Common abundant numbers include 6, 28, 496, and 8128
Conclusion
This program efficiently identifies abundant pairs by calculating the sum of proper divisors for each number and comparing with the original numbers. The algorithm works well for small to medium-sized numbers.
Advertisements
