Prime Numbers From 1 To N C Program

C Program To Print Prime Numbers from 1 To N

Learn How To Print Prime Numbers from 1 To N in C Programming Language. We have mentioned two methods below that focuses on While Loop and For Loop. You can alter this program to Display Prime Integers from 1 To 100.

Also Read: C Program To Check if a Number is Prime or Not

Method 1: C Program To Print Prime Numbers from 1 To N using For Loop


Method 2: C Program To Print Prime Numbers from 1 To 100 using While Loop

Output

C Program To Print Prime Numbers From 1 To N using For Loop

If you have any compilation error or doubts in this C Program To Generate Prime Integers from 1 To N, let us know about it in the Comment Section below.


Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

2 thoughts on “Prime Numbers From 1 To N C Program

  • August 20, 2016 at 4:00 pm
    Permalink

    Why do we have to initialize the for loop with 2? Why can’t we use use 0 instead of 2? The output for this Prime Number generation C Program is correct, but I am still confused.

    Reply
    • August 20, 2016 at 10:36 pm
      Permalink

      Jai, 2 is the smallest Prime Number. Hence, we start the loop with 2. Try starting it with 0 or 1. You will see the difference in the output.

      Reply

Join The Discussion