In C program, Use \"do...while\" and \"for\" loops to write a program that finds all prime...

Free

80.2K

Verified Solution

Question

Electrical Engineering

In C program, Use \"do...while\" and \"for\" loops to write aprogram that finds all prime numbers less than a specifiedvalue.

Answer & Explanation Solved by verified expert
4.3 Ratings (628 Votes)

#include

void main()

{

    int n,i,fact,j;

int a = 0;

    printf(\"Enter the Number\");

    scanf(\"%d\",&n);

    printf(\"Prime Numbers are: \n\");

do

    {

        fact=0;

        for(j=1; j<=n; j++)

        {

            if(i%j==0)

                fact++;

        }

        if(fact==2)

            printf(\"%d \" ,i);

a=a+1

    } while a

    getch();

}


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students