Hi, I was having a bit of trouble with a program that I was supposed to write for a homework assignment. The program's purpose is to find all of the perfect numbers between 1 and 100 (For those who dont know, a perfect number is a number is equal to the sum of all its divisors not including itself). The program runs, but it returns that there are no perfect integers. Here is the code I'm using:
Code:
/*
*File:perfect.c
*The program computes and displays all of the perfect numbers from 1 to 100.
*/
#include "stdafx.h"
#include <stdio.h>
bool check_perfect(int num);
main()
{
int num;
bool flag;
printf("The perfect numbers in the range 1-100:\n");
for (num=1;num<=100;num++);
{
flag=check_perfect(num);
if (flag==true) (printf("%d\n",num));
}
}
bool check_perfect(int num)
{
int sum,num1;
bool check;
sum=0;
for (num1=1;num1<=(num-1);num1++)
{
check=(num%num1==0);
if (check==true) sum=sum+num1;
}
if (num==sum) return (true);
else return (false);
}
Thanks for any help.