Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

What do you see as my responsibilities?

Answered: 1 week ago

Question

Do most of the borrowers own homes, have a mortgage, or rent?

Answered: 1 week ago