2025-03-06 23:47:59 +08:00

34 lines
846 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
1. 判断101-200之间有多少个素数并输出所有素数。判断素数的方法IsPrime用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。 --------------------------------------------------------*/
#include <stdio.h>
#include<math.h>
int IsPrime (int n)
{
int i=2;
for(i=2;i<=sqrt(n);i++)
/**********Program**********/
if(n%i==0){
return 0;
}
/********** End **********/
return 1;
}
int main( )
{
int i ;
for(i=100;i<=200;i++ )
{
if ( IsPrime( i) )
{
printf("% d",i);
}
}
return 0;
}