Question: determine the number of prime numbers between-and output all prime numbers.
Program Analysis: first understand what is a prime number, only the number divisible by 1 and itself, traverse the number between 101 and in a loop, and then use ~ For example, if the number is 200, we divide the number from 2 to 2 ~ The number between 112, as long as the integer here is not equal to 0, you can judge that this number is a prime number;
# Include <stdio. h> int main () {int I, j; int COUNT = 0; for (I = 101; I <= 200; I ++) {for (j = 2; j <I; j ++) {// If J can be rounded up by I in the out-of-loop if (I % J = 0) break;} // determine whether the loop exists in advance, if j <I indicates 2 ~ Between J, I has an integer. If (j> = I) {count ++; printf ("% d", I); // line feed, count with count, if (count % 5 = 0) printf ("\ n") ;}} return 0 ;}
Running result:
The other is to use a number to remove 2 to SQRT (This number). If it can be divisible, it indicates that this number is not a prime number, and vice versa.
#include <stdio.h>#include <math.h>int main(){ int i,j,k,leap=1; int count=0; for (i=101; i<=200; i++) { k=sqrt(i+1); for (j=2; j<=k; j++) { if (i%j==0) { leap=0; break; } } if (leap) { count++; printf("%d ",i); if (count % 5 == 0) printf("\n"); } leap=1; } return 0;}
Running result: