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

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

PHPz
Release: 2023-09-14 12:41:06
forward
1232 people have browsed it

在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;
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template