>it is supposed to find all perfect numbers from 1 to 100 and i'm supposed to make it "efficient".
Well, since you asked for something efficient and we know that there are only two perfect numbers from 1 to 100, we can either hard code it or use a lookup table:
Code:
#include <stdio.h>
int main ( void )
{
printf ( "%d %d\n", 6, 28 );
return 0;
}
Code:
#include <stdio.h>
static int perfect[] = { 6, 28, -1 };
int main ( void )
{
int i;
for ( i = 0; perfect[i] != -1; i++ )
printf ( "%d ", perfect[i] );
printf ( "\n" );
return 0;
}
-Prelude