title: C language. Factorial code (shortest possible)
body: <p>I wanted to code the shortest snippet possible for a factorial operation, using also the minimum number of variables (could not make it with less than 2) and the minimum of lines too. But, it is not working despite that the logic is, I think, good and correct, :/</p>
  
  <p>Here it is: say factorial of 5.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  main()   
  int x, i = 5;
  {
       while(i!=1)
       {
           i--;
           x *= i;
       }
  
       printf("%d",x); 
  }
  </code></pre>
  
  <p>So, let's depict what that code would do:</p>
  
  <p>inside the loop <code>i</code> turns 4,
  then we have <code>x = 5 * 4</code> which makes it 20.</p>
  
  <p>Next round <code>i</code> is 3, we have</p>
  
  <pre><code>x = 20 * 3
  </code></pre>
  
  <p>Next round <code>i</code> is 2</p>
  
  <pre><code>x = 60 * 2 
  </code></pre>
  
  <p>next <code>i</code> is 1   <code>x = 120 * 1</code>, so that is the factorial. </p>
  
  <p>I know there are bright brains out there who can come up with obfuscated code to do all that in half a line, but I would be satisfied just to find out why is giving me errors.</p>
  
  <p>UPDATE AFTER PEOPLE'S INPUT:</p>
  
  <p>it always yields 0 now, even if I change i!=2 </p>
  
  <pre><code>     main()
       {
          int x, i = 5;
          while(i!=1)
         {
           i--;
           x *= i;
         }
  
      printf("%d",x);
  
  
     }
  </code></pre>
  
  <p>THE FINAL SOLUTION AND EXPLANATION:</p>
  
  <p>I code in PHP and Java and today I wanted to do a quicky in C, so when I wrote this:</p>
  
  <p>int x, i = 5;</p>
  
  <p>I took for granted that it would initialize both to 5, as it does in PHP and JAVA, but it does not!</p>
  
  <p>So, if I do</p>
  
  <pre><code> #include&lt;stdio.h&gt;
  
  main()   
  int x = 5;
  int i = 5;
  {
       while(i!=1)
       {
           i--;
           x *= i;
       }
  
       printf("%d",x); 
       return (0);
  }
  </code></pre>
  
  <p>my code works. </p>
  
  <p>Thank you to all those who pointed the fundamental syntax errors. </p>
  
  <p>Syntax errors happen when one is not familiar with the language rules, but the most important is the logic of the code and that was correct.</p>