1 solutions

  • 0
    @ 2025-11-5 15:01:40

    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

    Information

    ID
    16341
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By