第一种:
int main ( )
{
int i, j;
int count = 0 ;
for ( i = 100 ; i <= 200 ; i++ ) {
for ( j = 2 ; j < i; j++ ) {
if ( i % j == 0 )
break ;
}
if ( i == j) {
printf ( "%d " , i) ;
count++ ;
}
}
printf ( "\n素数个数为%d\n" , count) ;
return 0 ;
}
第二种:
include<stdio.h>
int main ( )
{
int i, j;
int count = 0 ;
for ( i = 100 ; i <= 200 ; i++ ) {
int flag = 1 ;
for ( j = 2 ; j < i; j++ ) {
if ( i % j == 0 ) {
flag = 0 ;
break ;
}
}
if ( flag == 1 ) {
printf ( "%d " , i) ;
count++ ;
}
}
printf ( "\n素数个数为%d\n" , count) ;
return 0 ;
}
第三种:
# include <stdio.h>
int main ( )
{
int i, j;
int count = 0 ;
for ( i = 100 ; i <= 200 ; i++ ) {
int flag = 1 ;
for ( j = 2 ; j < i/ 2 ; j++ ) {
if ( i % j == 0 ) {
flag = 0 ;
break ;
}
}
if ( flag == 1 ) {
printf ( "%d " , i) ;
count++ ;
}
}
printf ( "\n素数个数为%d\n" , count) ;
return 0 ;
}
第四种:
# include <stdio.h>
# include <math.h>
int main ( )
{
int i, j;
int count = 0 ;
for ( i = 100 ; i <= 200 ; i++ ) {
int flag = 1 ;
for ( j = 2 ; j <= sqrt ( i) ; j++ ) {
if ( i % j == 0 ) {
flag = 0 ;
break ;
}
}
if ( flag == 1 ) {
printf ( "%d " , i) ;
count++ ;
}
}
printf ( "\n素数个数为%d\n" , count) ;
return 0 ;
}