I need the following c program to output prime number without using math functio
ID: 3638838 • Letter: I
Question
I need the following c program to output prime number without using math functions.As of right now it isn't out putting anything and I'm not sure why.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int startnum = 1; //program begins at 1
int endnum = 1000; //program ends at 1000
int divisor = 2;//divides
int number;
((int >= 1) (int <= 1000));
for (divisor = 2 ; divisor <= number ; divisor++);
{
if (number%divisor ==0);
}
if ( number == divisor)
printf("%d ", number);
return 0;
}
Explanation / Answer
#include
#include
int main()
{
int startnum = 1; //program begins at 1
int endnum = 1000; //program ends at 1000
int divisor = 2; //divides
int number, i;
bool flag = true;
number = i= startnum;
printf("Prime numbers greater than %d and less than %d are: ", startnum, endnum);
while (i <= endnum ) {
number++;
i++;
if (number != 2) {
for ( divisor=2; divisor < number; divisor++) {
if (number % divisor == 0) {
flag = false;
break;
}
}
}
if (flag) printf("%d ", number);
flag = true;
divisor = 2;
}
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.