0

ok i have this project that i have been working on to fin harmonic,powerful,amicable and perfect numbers

i have a few but im at a road block right now and would love some assisstance.

**POWERFUL NUMBERS**

```
#include <iostream>
using namespace std;
int main() {
int endRange = 500, var1, var2, var3, finalVar;
for (int counter = 4; counter < endRange = 500; counter++) {
var1 = counter;
var2 = 3;
var3 = 0;
finalVar = var1;
while (var1 % 2 == 0) {
var1 /= 2;
var3 += 1;
}
while ((var2 <= var1) && (var3 != 1)) {
var3 = 0;
while (var1 % var2 == 0) {
var1 /= var2;
var3 += 1;
}
var2 += 2;
}
if (var3 > 1)
cout << finalVar << ' ';
}
}
```

**AMICABLE NUMBERS**

```
int endnum = 2000;
struct amicable *ami;
ami = getAmicablePairs(startnum, endnum);
if(ami!=NULL)
{
printf("\n They are:");
printf("{");
for(i = 0; i<ami->size; i++)
{
printf("{%d, %d}",ami->amicablepair[i][0], ami->amicablepair[i][1]);
}
printf("}");
}
else
printf("Not Found:");
return 0;
}
struct amicable *getAmicablePairs(int startnum, int endnum)
{
int i,k=0,sums1=0,sums2=0;
struct amicable *ami;
ami->size=0;
if(startnum<0 || endnum<0 || endnum>15000 || startnum>endnum)
return NULL;
else
{
for(i=startnum;i<=endnum;i++)
{
sums1=sumdivisors(i);
sums2=sumdivisors(sums1);
if(sums2==i && i<sums1)
{
ami->amicablepair[k][0]=i;
ami->amicablepair[k][1]=sums1;
k++;
}
sums2=0;
sums1=0;
ami->size=k;
}
if(ami->size==0)
return NULL;
else
return(ami);
}
}
int sumdivisors(int num)
{
int i,sum=0;
for(i=1;i<num;i++)
{
if(num%i==0)
sum+=i;
}
return(sum);
}
```

**HAMONIC NUMBERS**

```
#include <stdio.h>
double seq(double x);
double seq(double x) {
double temp=0;
if (x==0)
return 0;
return 1/x + seq(x-1);
}
int main() {
double x, y;
while (x != 0) {
printf("Please enter a number:\n");
scanf("%lf", &x);
y = seq(x);
printf("The sequence of that number is: %lf\n", y);
}
system("PAUSE");
return 0;
}
```

**PERFECT NUMBERS**

```
#include <limits.h>
#include <iostream>
using namespace std;
int main()
{
char buf[4096]; //where to store the numbers and than print only primes
char *cp; //char pointer
bool is_prime; //clearly a bool variable
unsigned num, i, sum; //unsigned max is around 4 billion
for (num = 1; num <= UINT_MAX; num++)
{
cp = buf;
is_prime = true;
cp += sprintf(cp ,"%u: ", num) ;//just naming the line with a number "num"
for(i = 2; i < num ; i++)
{
if(0 == (num % i))//if num evenly divides i, add it to print line
{
is_prime = false;
cp += sprintf(cp, "not prime\n");//writes everything that is prime
break;
cp += sprintf(cp, "%u ", i);//print the factors
}//close if
}//close for
cp += sprintf(cp, "\n");
if (is_prime)
printf("%s", buf);
}//close for
return 0;
}//main
```

can someone check if these are actually running correctly please. i was trying at school and it worked but my laptop is 64bit and the os is also 64bit so i dnt have a proper compiler.

anyone can recommend a decent compiler as well one that can work on a 64 bit os

*Edited 6 Years Ago by WaltP*: Added CODE Tags