Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Mathematics ProgramRSS Feeds

PROGRAM TO PRINT ALL THE PERFECT NUMBERS BETWEEN 1 AND 2000

Posted By: Waggoner Fischer     Category: C Programming     Views: 4072

A PERFECT NUMBER IS ONE, WHICH IS EQUAL TO THE SUM OF ITS FACTORS OTHER THAN ITSELF. WRITE A PROGRAM TO PRINT ALL THE PERFECT NUMBERS BETWEEN 1 AND 2000.

Code for PROGRAM TO PRINT ALL THE PERFECT NUMBERS BETWEEN 1 AND 2000 in C Programming

#include<stdio.h>
#include<conio.h>
void main()
{
    longint n,i,j,sum;
    clrscr();
    printf("\n");
    for(i=1;i<=2000;i++)
    {
        sum=0;
        for(j=1;j<i || j==1;j++)
            if(i%j==0)
                sum=sum+j;
        if(i==sum)
        {
            for(j=1;j<i || j==1;j++)
                if(i%j==0)
                printf("%ld ,",j);
            printf("\n THE SUM OF THIS FACTORS ARE %ld .\n",sum);
            printf("SO %ld IS PERFECT NUMBER \n\n",i);
        }
    }
    getch();
}




****************************** OUTPUT *********************************

1 ,
 THE SUM OF THIS FACTORS ARE 1 .
SO 1 IS PERFECT NUMBER

1 ,2 ,3 ,
 THE SUM OF THIS FACTORS ARE 6 .
SO 6 IS PERFECT NUMBER

1 ,2 ,4 ,7 ,14 ,
 THE SUM OF THIS FACTORS ARE 28 .
SO 28 IS PERFECT NUMBER

1 ,2 ,4 ,8 ,16 ,31 ,62 ,124 ,248 ,
 THE SUM OF THIS FACTORS ARE 496 .
SO 496 IS PERFECT NUMBER


************************************************************************
  
Share: 



Waggoner Fischer
Waggoner Fischer author of PROGRAM TO PRINT ALL THE PERFECT NUMBERS BETWEEN 1 AND 2000 is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!