BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to check abundant number

Last Updated: May 16, 2024 by Chaitanya Singh | Filed Under: C Programs

In this tutorial, we will write a C program to check if a number is abundant number or not. A number is called an abundant number if sum of its proper divisors (excluding itself) is greater than the number itself.

Note: Proper divisors are numbers that divide the given number without leaving a remainder.

For example: Let’s check whether number 12 is abundant or not. Proper divisors of 12 are 1, 2, 3, 4, and 6. The sum of these proper divisors is 1 + 2 + 3 + 4 + 6 = 16. Since the sum of proper divisors (16) is greater than the number itself (12). Thus, we can say that 12 is an abundant number.

C Program to check if a number is abundant or not

#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;
}
}

// Check if the sum of proper divisors is greater than the number
return sum > num;
}

int main() {
int num;

// Input number from user
printf("Enter a number: ");
scanf("%d", &num);

// Check if the number is an abundant number
if (isAbundant(num)) {
printf("%d is an abundant number.\n", num);
} else {
printf("%d is not an abundant number.\n", num);
}

return 0;
}

The function isAbundant() takes integer number as argument and returns 1 if the number is abundant else it returns 0.

In this function, a for loop finds the proper divisors and add those to the variable sum. Then, it compares this sum with the number itself to determine if it’s abundant or not

Output:

Output 1:

Enter a number: 12
12 is an abundant number.

Output 2:

Enter a number: 7
7 is not an abundant number.

Top Related Articles:

  1. C Program to find greatest of three numbers
  2. C Program to concatenate two strings without using strcat
  3. Hello World Program in C
  4. C Program to calculate Area of an Equilateral triangle
  5. C program to print numbers divisible by 3 and 5 from 1 to 100

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap