Have a Read!

Hi Everyone.
The idea for this page is to provide new c users simple c tutorials to learn how to develop the logic and more importantly correct way to write syntax.
ENJOY !!!

Saturday, January 29, 2011

C PROGRAM FOR ARMSTRONG NUMBER UPTO LIMIT

#include<stdio.h>
int main () {
int num,n,sum,r,limit;
printf("ENTER THE LIMIT\n");
scanf("%d",&limit);
printf("Armstrong numbers upto given limit are:\n");
for(num=1;num<limit;num++)
{
    n = num;
    sum = 0 ;
    while (n!=0)
        {
            r=n%10;
            sum=sum+(r*r*r);
            n=n/10;
        }
    if(sum==num)
        {printf("%7d\n",num);}
}
return 0;
}

3 comments:

  1. The above code isn't working for limit more than 1000 .... Can you give any other solution for this???

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete

Related Posts with Thumbnails