This is a perfect number generator, when you start from 0 to 100 it should find 6 and 28, but for some reason it only recognizes 6 as a perfect number. Why doesn't it output 28? Danke!
Code:
#include <stdio.h>
#include <stdlib.h>
int check;
int isAFactor(int i, int o);
int main()
{
int startval;
int endval;
int o;//outer loop
int i = 1;//inner loop
int check2 = 0; //if remains 0, no perfect numbers.
int add = 0;
printf("Enter starting integer: ");
scanf("%d", &startval);
printf("\nEnter ending integer: ");
scanf("%d", &endval);
o = startval;
for(;o<=endval;o++)
{
for(; i<=o/2; i++)
{
check = isAFactor(i,o);
if (check == 0)
{
add = add + i;
}
}
if(add == o && o!=0)
{
printf("\n%d is a perfect number.\n", o);
check2 = 1;
}
}
if(check2 ==0)
{
printf("\nNo Perfect Numbers found between %d and %d.", startval, endval);
}
return 0;
}
int isAFactor(int i, int o)
{
check = o%i;
return check;
}