Project Euler Problem 7

Problem 1:- http://projecteuler.net/problem=7

 

Solution :- 

#include <stdio.h>
#include <math.h>

int prime(num){
  int i;

  if (num==2)
    return 1;

  for (i=2;i<sqrt(num)+1;i++){
    if (num%i==0)
      return 0;
    }

  return 1;
}

int main(){
  int i,c,ans;
  ans=0;
  c=0;

  for (i=2;i<200000;i++){
    if (prime(i)==1){
      c++;
      ans=i;
    }
    if (c==10001){
      break;
    }
  }

  printf(“%dn”,ans);
  return 0;
}

  Output :- 104743

At First you can try to solve this problem if you can’t than see this code & find what’s your problem . If you copy paste this code you could not improve yourself in programming .

Posted by Shipu Ahamed

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.