Guest_imported
New member
- Jan 1, 1970
- 0
Im trying to write a program that finds all perfect numbers up to 1 billion...
Its not working... so can someone help fix it?
#include <stdio.h>
#include <conio.h>
long x, loops, i, y, a, num, sum;
/*function prototype*/
long Perfect(int x);
int main()
{
/*Calls Function Perfect(x)*/
a = Perfect(x);
num = a;
/*finds divisors of perfect numbers*/
for(i=1; i <= num/2; i++)
{
if(!(num % i))
sum += i;
}
printf("%ld", sum);
return 0;
}
/*Return Function*/
long Perfect(int x)
{
loops = 0;
while (loops < 1000000000)
{
if ((2^x)-1 % 1)
y = (2^(x-1))*((2^x)-1);
loops++;
}
return y;
}
/*End of Program*/
Its not working... so can someone help fix it?
#include <stdio.h>
#include <conio.h>
long x, loops, i, y, a, num, sum;
/*function prototype*/
long Perfect(int x);
int main()
{
/*Calls Function Perfect(x)*/
a = Perfect(x);
num = a;
/*finds divisors of perfect numbers*/
for(i=1; i <= num/2; i++)
{
if(!(num % i))
sum += i;
}
printf("%ld", sum);
return 0;
}
/*Return Function*/
long Perfect(int x)
{
loops = 0;
while (loops < 1000000000)
{
if ((2^x)-1 % 1)
y = (2^(x-1))*((2^x)-1);
loops++;
}
return y;
}
/*End of Program*/