Question: Program to printf all prime numbers from 1 to 300: Hi there, I am writing a program to get all prime numbers from 1 to

Program to printf all prime numbers from 1 to 300:

Hi there, I am writing a program to get all prime numbers from 1 to 300, I would like to use a variable 'Count' instead of break as usually seen in other examples. I am not able to get the desired result and I think it has something to do with parenthesis use. Please see below my code:

int main ()

{

int n=0, i, count = 0;

for (i>1; i<=300; i++)

{

for (n>1; n<=i; n++)

{

if (i % n == 0)

{

count ++;

}

}

if (count <=2)

{

printf("%d", i);

}

}

}

I want the if condition to printf the number if this number is exactly divisible no more than two times, which would represent itself and 0.

Can you please have a look at my code and let me know what needs to be corrected?

Thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!