Programming find prime numbers 100

Description: prime number is divisible by itself and can be 1, the other can not be divisible by an integer number. Programming seek within 100 primes.

#include<iostream>
using namespace std;
int main()
{
    int flag;
	for(int i=2;i<=100;i++)
	{  flag=0;
		 for(int j=2;j<i;j++)
		 {
		 	if(i%j==0) flag=1;
		 }		 
		 if(flag==0) cout<<i<<" ";
		 
	}
  return 0;
}

  operation result:

 

Guess you like

Origin www.cnblogs.com/xxas2015/p/11300551.html