Outputting the algorithm of instance code of the prime number within 1000

  • 2020-04-02 00:49:54
  • OfStack

The code is as follows:

#include "stdafx.h"
#include <iostream> 
#include <math.h>
bool IsSushu(int n)
{
 bool IsSushuFlg = true;
 if( n <= 1)
 {
  return false;
 }
 for( int i = 2; i <= (int)sqrt((double)n); i++ )
 {
  if( 0 == n % i )
  {
   IsSushuFlg = false;
   break;
  }
 }
 return IsSushuFlg;
}
#define N 1000
int main()
{
 printf("Su shu is: /n");
 for( int i = 2; i < N; i++)
 {
  bool IsSushuFlg = IsSushu(i);
  if( IsSushuFlg )
  {
   printf("%d /n", i);
  }
 }

 system("pause");
 return 0;
}

Related articles: