Pages

Subscribe:

Armstrong Number In C

An Armstrong number is a three digits( 0-999 ) integer number,each digit cubes of the sum  is equal to the number itself. Armstrong numbers : 0,1,153,370,371,407.


Example : " ^  " power sign . e.g : 2^3=2*2*2=8
  1. 0^3=0
  2. 1^3=1
  3. 1^3+5^3+3^3=153
  4. 3^3+7^3+0^3=370
  5. 3^3+7^3+1^3=371
  6. 4^3+0^3+7^3=407
To Check Whether Given  Number  Is Armstrong or Not
Program :


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,b,am=0,c,d,p,e;
char ch;
do{

    clrscr();
    printf("\n\t Enter no(0-999):");
    scanf("%d",&n);
    d=e=n;
    for(b=0;n>0;b++)
    {
        n=n/10;
    }

    while(d>0)
    {
        c=d%10;
        p=pow(c,b);
        am=am+p;
        d=d/10;
    }
     if(am==e)
           printf("\n\t <%d> Armstrong Number",e);
    else
          printf(" \n\t<%d> Not Armstrong Number",e);

          printf("\n\t Continue(y/n) :");

ch=getch();
}while(ch=='Y'||ch=='y');
}


Output :


No Preview






If you have any Further Information and Quires about this Article don't hesitate to comment in comment box below.
                                                           AND

 If you like this article , like our Facebook like page and click  +1 to support 123techguide
comments powered by Disqus
 

Listed In

Bloggers - Meet Millions of Bloggers http://Link-exchange.comxa.com
Blog Search: The Source for Blogs Internet Blogs

Disclaimer

The contents in this blog are taken from various sources available over the internet, therefore we do not gurantee of it's accuracy, if you find any of the content in the blog is infringing it's copyright, please do email us on '123techguide@gmail.com' and we will make sure to remove the same from the blog at the earliest.