Page Rank Checker

Sunday 1 June 2014

Calculate Armstrong Numbers Program In C


This article is from solution of Let Us C by Yashwant Kanetkar. I also posted many another articles regarding solutions of Let Us C. If you have any problem regarding solution then give comment, I will surely reply your question.

Q. Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each digit of the number is equal to the number itself, then the number is equal to the number itself, then the number is called an Armstrong number. For example, 153=(1*1*1)+(5*5*5)+(3*3*3).

Ans.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int num=1, hun, dec, unit;
    for(;num<=500;num++)
    {
        hun=num/100;
        dec=(num-hun*100)/10;
        unit=(num-(hun*100)-(dec*10))/1;
        if((hun*hun*hun)+(dec*dec*dec)+(unit*unit*unit)==num)
        printf("\n%d is a Armstrong number",num);
    }
    getch();
}