Q10 Write a program to print all prime numbers from 1 to 300. (Hint: Use Nested loops, break and continue)

Program: 103

Write a c program to print all prime numbers from 1 to 300. (Hint: Use Nested loops, break and continue)

Output:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
53 59 61 67 71 73 79 83 89 97 101 103 107 109
113 127 131 137 139 149 151 157 163 167 173 179 181 191
193 197 199 211 223 227 229 233 239 241 251 257 263 269
271 277 281 283 293

Lokesh Kumar

Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.

2 thoughts on “Q10 Write a program to print all prime numbers from 1 to 300. (Hint: Use Nested loops, break and continue)

  • December 14, 2021 at 12:39 pm
    Permalink

    Bro can you please explain that in 2nd for loop why you use n/2

    Reply
  • January 21, 2023 at 6:15 pm
    Permalink

    Because if a number is not divided with the number till its half, then it will not be divided from further numbers. So we will check only till half of the number.

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.