Im trying to write a program to print all the primes from 1 to 100. I am however required to use a boolean function. My problem is that all the odd #s except 1 also appear in the output.
#include "stdafx.h"
#include <stdio.h>
#include "strlib.h"
#include "genlib.h"
#include "random.h"
#include <math.h>
bool IsPrime(int num);
int main()
{
int num;
num=2;
printf("The prime numbers in the range of 1-100 are:\n");
printf("%d\n", num);
for (num=3;num<=100;num+=2)
{
if (IsPrime(num)==(true));
{
printf("%d\n", num);
}
}
}
bool IsPrime(int num)
{
int i;
double limit;
if (num<=1) return (false);
if (num==2) return (true);
if (num%2==0) return (false);
limit=sqrt(double(num))+1;
for (i=3;i<=limit;i+=2)
{
if (num%i==0) return (false);
}
return (true);
}