Write a C program to
Print 1st 30 Perfect numbers starting from 0 and calculate sum.
Hints:
Today the usual definition of a perfect number is in terms of its divisors,
but early definitions were in terms of the 'aliquot parts' of a number. An aliquot part of a number is a proper quotient of the
number. So for example the aliquot parts of 10 are 1, 2 and 5. These occur
since 1 = 10/10, 2 = 10/5, and 5 = 10/2.
Note that 10 is not an aliquot part of 10 since it is not a proper quotient,
i.e. a quotient different from the number itself. A perfect number is defined
to be one which is equal to the sum of its aliquot parts. The four perfect numbers 6, 28, 496 and 8128 seem to have been known from ancient times and there is no record of these discoveries.
6 = 1 + 2 + 3,
28 = 1 + 2 + 4 + 7 + 14,
496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248
8128 = 1 + 2 + 4 + 8 + 16 + 32 + 64 + 127 + 254 + 508 + 1016 + 2032 + 4064
If as many numbers as we please beginning from a unit be set out continuously in double proportion, until the sum of all becomes a prime, and if the sum multiplied into the last make some number, the product will be perfect.
Here 'double proportion' means that each number of the sequence is twice the preceding number. To illustrate this Proposition consider 1 + 2 + 4 = 7 which is prime. Then
(the sum) × (the last) = 7 × 4 = 28,
which is a perfect number. As a second example, 1 + 2 + 4 + 8 + 16 = 31 which is prime. Then 31 × 16 = 496 which is a perfect number.
Now Euclid gives a rigorous proof of the Proposition and we have the first significant result on perfect numbers. We can restate the Proposition in a slightly more modern form by using the fact, known to the Pythagoreans, that
1 + 2 + 4 + ... + 2k-1 = 2k - 1.
The Proposition now reads:-
If, for some k > 1, 2k - 1 is prime then 2k-1(2k - 1) is a perfect number.
Source Code:
#include<stdio.h>
using namespace std;
int j,i;
int perfect()
{
int sum=0,count=0,sum1=0;
for( j=1; j <= 50000; j++ )
{
i =1;
sum = 0;
while ( i < j )
{
if ( j%i = =0 )
sum = sum+i ;
i++;
}
if( sum = = j )
{
cout << j << endl;
sum1 += j ;
}
}
cout << "The sum of the first 4 perfect number is: ";
cout << endl;
return sum1;
}
int main( )
{
cout << "First 30 perfect number is:"<< endl;
cout << perfect( );
return 0;
}
#include
উত্তরমুছুনmain()
{
int start,end,num,p=1,i;
scanf("%d",&start);
scanf("%d",&end);
for(num=start;num<=end;num++)
{
for(i=2;i<num;i++)
{
if(num%i==0)
{
p=0;
break;
else
p=1;
}
if(p==1)
printf("%d\n",num);
}
}
}
/* First 30 perfect number but i findout 4 perfect number and sum because,it take long time*/
উত্তরমুছুন/* Author Name:Md.naimul hasan shohan */
#include
using namespace std;
int j,i; //globally declared
int perfect()
{
int sum=0,count=0,sum1=0;
for(j=1;j<=50000;j++){
i=1;
sum = 0;
while(i<j){
if(j%i==0)
sum=sum+i;
i++;
}
if(sum==j)
{
cout<<j<<endl;
sum1+=j;
}
}
cout<<"The sum of the first 4 perfect number is:";
cout<<endl;
return sum1;
}
int main()
{
cout<<"First 30 perfect number is:"<<endl;
cout<<perfect();
return 0;
}
Without Range print perfect numbers list:
উত্তরমুছুনID:201210659
batch 39th
#include
using namespace std;
main()
{
int b,a;
{
for(b=1;;b++)
{
int c=0;
for(a=1;a<b;a++)
{
if(b%a==0)
c=c+a;
}
if(c==b)
cout<<b<<endl;
}
}
}
without range, print list of perfect numbers:
উত্তরমুছুনID:201210659
Batch=39th
#include
using namespace std;
main()
{
int b,a;
{
for(b=1;;b++)
{
int c=0;
for(a=1;a<b;a++)
{
if(b%a==0)
c=c+a;
}
if(c==b)
cout<<b<<endl;
}
}
}
#include
উত্তরমুছুনusing namespace std;
int main()
{
int sum=0,num,i,j;
for(j=1; ;j++)
{
num=j;
for(i=1;i<=num/2;i++)
{
if(num%i==0)
sum+=i;
}
if(sum==num)
cout<<"perfect="<<num<<endl;
sum=0;
}
}