1 条题解

  • 0
    @ 2025-4-12 21:33:54

    C :

    #include<stdio.h>
    #include<math.h>
    int main()
    {
    	int i,j,s=0;
    	for(i=100;i<=200;i++)
    	{
    		for(j=2;j<=sqrt(i);j++)
    		{
    			if(i%j==0)break;
    		}
    		if(j>sqrt(i)){s++;if(s==1)printf("%d",i);else printf(" %d",i);};
    	}
    	return 0;
    }
    

    C++ :

    #include <iostream>  
    #include<cmath>                            //在Dev C++中可调用数学函数库cmath
    using namespace std;
    int main ()
    {
      int x;
      for (int i=100;i<=200;++i)
      {
         x=2;
         while(x<=floor(sqrt(i))&&(i%x!=0))    //floor为取整函数,需调用math.h库
         x=x+1;                       //在枚举的范围内并且没有出现约数则继续枚举
         if ( x>floor(sqrt(i)))
           cout<<i<<" ";
      }
      return 0;
    }
    
    
    • 1

    信息

    ID
    672
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者