Home  >  Article  >  Backend Development  >  In C language, the translation of "Abundant Number" is "excess number"

In C language, the translation of "Abundant Number" is "excess number"

PHPz
PHPzforward
2023-09-14 12:41:061128browse

在C语言中,"Abundant 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.

Program to find whether numbers are rich

#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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete