SoFunction
Updated on 2025-03-10

C language implements all complete numbers within 1000 output

All complete numbers within 1000 of C language output

#include <>

int main()
{
    int i,j;
    
    printf("All finished numbers within 1000:");
    
    for(i=1;i<=1000;i++)
    {
        int sum=0;
        for(j=1;j<i;j++)
        {
            if(i%j==0)
                sum = sum+j;
        }
        if(sum==i)
            printf("%d  ",i);
    }
    printf("\n");
           
    return 0;
}

Output result:

All completed numbers within 1000: 6 28 496

C language outputs all complete numbers between two numbers

Write a program, enter two positive integers m and n (1<=m,n<=10000), and output all the complete numbers between the two numbers.

Requires the function perfectNumber(?) to be defined and called to determine whether n is a complete number.

Complete number:The sum of all true factors is exactly equal to its natural number.

For example: 28 is a complete number, which has true factors 1, 2, 4, 7, 14, and the addition is equal to 28.

// Perfect number, a number is exactly equal to the sum of its factors#include&lt;&gt;

void perfectnum(int m,int n);

int main() {
    int m,n;
    printf("Enter two positive integersmandn(1&lt;=m,n&lt;=10000):");
    scanf("%d %d",&amp;m,&amp;n);
    perfectnum(m,n);
    return 0;
}

void perfectnum(int m,int n)
{
    int a;
    int i;
    int sum;
    for(a=m;a&lt;n;a++)
 // Find the perfect number of m-n    {
        sum=0;
        for (i=1; i&lt;=a/2; i++)
//Reduce the number of cycles and judge all factors by half.        {
            if(a%i==0)
                sum=sum+i;
        }
        if (a==sum) {
            printf("%d is the perfect number\n",a);
        }
    }
}


Output

Enter two positive integers m and n(1<=m,n<=10000):0 1000
0 is the perfect number
6 is the perfect number
28 is the perfect number
496 is the perfect number

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.