title: Time taken for a loop to run
body: <p>I am new to programming. I was trying a program to print the nth prime number. The code is as given below:  </p>
  
  <pre><code>##program to print the nth prime number
  nreq=input("Enter a number ")  
  pctr=0 ##counter of the prime numbers
  num=2
  
  while pctr!=nreq:
      ctr=0 ##counter
      i=2
      while i&lt;=num:
          if num%i==0:
              ctr=ctr+1
          i=i+1
      if ctr==1:
          pctr=pctr+1
      if pctr==nreq:
          break
      num=num+1
  
  
  print 'the {}th prime number is {}'.format(nreq,num)  
  </code></pre>
  
  <p>I tried the same algorithm in both python and C. For larger numbers the time taken in python was much greater for the output as compared to C. Why did this occur? Can someone please explain the difference in which both of them execute?</p>
  
  <p>My code in C was the following:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  
  void main()
  {
  
  int num=2,nreq,ctr=0,pctr=0,i;
  
  printf("enter the number of prime required");
  scanf("%d",&amp;nreq);
  
      while(pctr!=nreq)
  {
  
      ctr=0;
      for(i=2;i&lt;=num;i++)
          if(num%i==0)
              ctr++;
  
      if(ctr==1)
          pctr++;
  
      if(pctr==nreq) 
          break;
      num++;
  }
  
  printf("the %dth prime number is %d",nreq,num);
  }
  </code></pre>