title: Simple C++ code to generate Armstrong numbers
body: <p>The following is my simple attempt at generating <a href="http://oeis.org/A005188" rel="nofollow">Armstrong numbers</a>. But it only outputs "1". What might be wrong?</p>
  
  <pre><code>#include&lt;stdio.h&gt; 
  #include&lt;conio.h&gt; 
  #include&lt;iostream.h&gt;
  
  int main() 
  { 
      clrscr();
      int r; 
      long int num = 0, i, sum = 0, temp; 
  
      cout &lt;&lt; "Enter the maximum limit to generate Armstrong number "; 
      cin &gt;&gt; num;
      cout &lt;&lt; "Following armstrong numbers are found from 1 to " &lt;&lt; num &lt;&lt; "\t \n"; 
  
      for(i=1;i&lt;=num;i++) 
      { 
          temp = i; 
          while( temp != 0 ) 
          { 
              r = temp%10; 
              sum = sum + r*r*r; 
              temp = temp / 10; 
          } 
  
          if ( i == sum ) {
              cout &lt;&lt; i;
              sum = 0; 
          }
      } 
  
      getch(); 
  
      return 0; 
  }
  </code></pre>