In this, you first need to understand how prime is obtained, you can divide yourself by 2 to your previous position, according to the remainder of the situation to determine whether a prime or composite.
Optimization:
(1) Starting from 101, each time add 2, so as to improve the efficiency of one times.
(2) divided by its own square root can also be.
#include <stdio.h> #include <math.h> #include <stdlib.h> void prime () {
int num = 100;
int k = 0;
int i = 2; for (num = 101; num < 201; num++)
{ k = num / 2; for (; i < num; i++) { if (num % i != 0) //all integers not--> primes, output, start to judge next number {
printf ("%d ", num); break; } else //can be divisible by a number--> composite numbers, Then this number can't be Sue lost, start judging the next number {
break; }
&NBSP;&NBSP}  }} int main () { prime ();
system ("pause");
return 0; }