In: Electrical Engineering
Use "do...while" loops to write a program that finds all prime numbers less than a specified value.
%Program to find follows
#include <stdio.h>
#include <math.h>
int main(void)
{ printf("Please enter a maximum value...\n"); int max;
scanf("%d", &max);
int current = 4;
int checker = 2;
do{
if(checker >
sqrt((double)current))
{
checker = 2;
printf("%d is prime\n",current);
current++;
}
else if(current %
checker == 0)
{
checker = 2;
printf("%d is NOT prime\n",current);
current++;
}
else
checker++;
}while(current < max);
}
Output:
I have entered max value is 20.