ProjectEuler Problem-7 Solution

Problem :

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?

Solution :

#include<iostream>
using namespace std;

int main()
{
 int p=14,pos=6;
 while(1)
 {
  int flag=1;
  for(int i=2;i<=p/2;i++)
  {
      if(p%i==0)
      {
      flag=0;
      break;
      }
  }
  if(flag==1)
  pos++;
  if(pos==10001)
  break;
 p++;
    }
 cout<<"Number:"<<p;   
 return 0;   
}

No comments: