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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started