Thread: having trouble with armstrong program code

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    13

    Smile having trouble with armstrong program code

    program to print armstrongs numbers between 1 and 500.

    Code:
    #include<stdio.h>
    int main()
    {
    int m,n,sum=0,a;
    for(n=1;n<=500;n++)
    {
       m=n;
         while(m!=0)
           {
             a=m%10;
             sum=sum+(a*a*a);
             m=m/10;
           }
           if(n==sum)
          printf("%d\n",n);
          
    }
    }
    the above code is not working..please tell me where did it went wrong........

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Presumably you want to reset sum at some point inside your for loop before you start adding to it.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    13
    Quote Originally Posted by tabstop View Post
    presumably you want to reset sum at some point inside your for loop before you start adding to it.

    thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. how do I morse code converting program
    By panfilero in forum C Programming
    Replies: 17
    Last Post: 10-29-2005, 09:16 PM
  3. Writing code for a program in C
    By Sure in forum C Programming
    Replies: 7
    Last Post: 06-11-2005, 01:33 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM