Tuesday, 7 April 2015

C Program to check whether given number is ARMSTRONG or NOT.

#include<stdio.h>
#include<conio.h>
main()
{
                int n,n1,sum=0,x;
                clrscr();
                printf("Enter the number\n");
                scanf("%d",&n);
                n1=n;
                while(n>0)
                {
                                n=n%10;
                                sum=sum+x*x*x;
                                n=n/10;
                }
                if(n1==sum)
                {
                                printf("\n%dis a Armstrong number.",n1);
                }
                else
                {
                                printf("\n%d is not an Armstrong number.",n1);
                }
}

No comments:

Post a Comment