Search & Find out

Thursday, November 26, 2009

Armstrong Number

 To find whether the entered number is armstrong no. or not


 #include "stdio.h"
#include "conio.h"
void main ()
{
    int a,b;
    int armstrong(int);
    clrscr();
    printf ("Enter a number: ");
    scanf ("%d",&a);
    b=armstrong (a);
    if (b==1)
        printf ("The number is armstrong");
    else
        printf ("The number is not armstrong");
getch ();
}
int armstrong (int x)
{
    int q,r,m,R;
    clrscr ();
    m=x;
    for (R=0;x>0;)
    {
        q=x/10;
        r=x%10;
        R=R+(r*r*r);
        x=q;
    }
    if (R==m)
        R=1;
    else
        R=0;
    return (R);
}



Download the executable (.exe)  file for this program..
download

0 comments:

Post a Comment

 

My Blog List

Term of Use