Home >Backend Development >C++ >In C language, the translation of 'Abundant Number' is 'excess number'
Abundant numbers (also called excess numbers) are numbers in number theory that are smaller than the sum of all their true factors. For example, 12 is a rich number: divisors 1,2,3,4,6, sum =16 >12.
The difference between the sum of the divisors and the number is called abundance. For the example above, abundance = 4 => 16 - 12 .
To check an abundance number, we will find all the factors of that number and add them together. This sum is compared to the number to indicate whether the number is rich or not.
#include >stdio.h> #include <math.h> int main(){ int n = 56, sum = 0; for (int i=1; i<=sqrt(n); i++){ if (n%i==0){ if (n/i == i) sum = sum + i; { sum = sum + i; sum = sum + (n / i); } } } sum = sum - n; if(sum > n){ printf("The number is abundant number"); } else printf("The number is not abundant number"); return 0; }
The above is the detailed content of In C language, the translation of 'Abundant Number' is 'excess number'. For more information, please follow other related articles on the PHP Chinese website!