title: Finding maxium factorial n what intiger allows! C++
body: <p>Sorry for bad English.<br>
  So my problem is that i need to find all possible factorials starting from 1. 
  I need it to stop when Int have maximum memory used and print out maximum factorial value. My code is pretty simple, but i do not know how to get to stop loop when it reach maximum of Intiger values. </p>
  
  <pre><code> #include &lt;iostream&gt;
   #include&lt;climits&gt;//
   #include &lt;cmath&gt;
   using namespace std;
  
   int main() {
  
  int k,n=0;
  unsigned  int factorial = 1;
  unsigned  int factorial2=1;
  unsigned  uval=INT_MAX;
  
  cout &lt;&lt; "Ievadi koeficentu k: ";
  cin &gt;&gt; k;
  for(int i = 1; i&lt;=k; ++i) {
      factorial *= i;
  }
  cout &lt;&lt; "Ievadita koeficenta " &lt;&lt; k &lt;&lt; " faktorials " &lt;&lt; " = " &lt;&lt;factorial;
  
  cout &lt;&lt; "\nVisi iespejamie faktoriali no 1 - n: ";
  for(int s = 1; s&lt;=uval; ++s) {
  
      factorial2 *= s;
     if( s &lt; uval / factorial2 ){
        cout  &lt;&lt;" \nkoeficenta " &lt;&lt; s &lt;&lt; " faktorials ir ==&gt; " &lt;&lt;factorial2;
     }
  }
  
  
  
  
  return 0;
  }
  </code></pre>
  
  <p>The problem is that the loop is going to calculate factorial to all UINT_MAX values, and most of the output will be 0 becouse memory is overloaded. 
  But it should stop before it goes bigger that UINT_MAX memory! 
   Hope you all understand my problem and will help me with this.</p>