[C language] to determine whether a positive integer number for the End

What is the number of completion?

If a number is equal to the sum of its factors, the number is called "End number" (or "full number").

For example, a factor of 6, 2,3, and 6 + 2 + 1 = 3, 6 is therefore "count them."

Block Diagram: m

 problem analysis

The definition of the end, the key to this problem solution is calculated from the chosen integer m (in the range of m is not fixed) factor (factor that all can be divisible this number), each factor accumulated into the variable sum (record all and the factor), if the sum is equal to m, m is a complete number can be confirmed, otherwise the number is not complete.

Code:

#include<stdio.h>
int main()
{
    int m, n, sum = 0;
    printf ( " Please enter a positive integer: \ the n- " );
    scanf_s("%d", &m);
    for (n = 1; n < m - 1; n = n + 1)
        if (m % n == 0)
            sum = sum + n;
    if (m == sum)
        the printf ( " The number is the number of complete \ n- " );
     the else 
        the printf ( " The number is not the number of complete \ n- " );
}

 

Guess you like

Origin www.cnblogs.com/HGNET/p/11884657.html