Program to Check if a Number is an Abundant Number in C
Abundant Number
An abundant number is a number for which the sum of its proper divisors is greater than the number itself. For example, 12 is an abundant number because its divisors (1, 2, 3, 4, 6) sum to 16, which is greater than 12.
We will explore a method to check if a given number is an abundant number using C programming.
Method: Using a for Loop
We iterate through all numbers less than the given number to find its divisors and sum them up.
#include <stdio.h> int isAbundant(int num) { int sum = 0; // Calculate the sum of proper divisors for (int i = 1; i <= num / 2; i++) { if (num % i == 0) { sum += i; } } return (sum > num); } int main() { int num; printf("Enter a number: "); scanf("%d", &num); if (isAbundant(num)) printf("%d is an Abundant number", num); else printf("%d is not an Abundant number", num); return 0; }
Output:
Enter a number: 12 12 is an Abundant number