C ++ program:
# include <iostream.h> # include <conio.h> # include <math.h> void main () { clrscr(); int a,b=0,sum=0; long int n; cout<<"Enter the number to be checked\n "; cin>>n; if(n<1) { cout<<"\nThe number should be greater than 0"; } else { a=n; //counting the digits while (a>0) { a=a/10; b++; } a=n; //adding up bth power of digits while(a>0) { sum=sum+pow(( a%10) ,b); a=a/10; } if(sum==n) cout<<"\nThe number is an ARMSTRONG number"; else cout<<"\nThe number is NOT an ARMSTRONG number"; } getch(); }
C Program:
# include <stdio.h> # include <conio.h> # include <math.h> void main () { clrscr(); int a,b=0,sum=0; long int n; printf("Enter the number to check\n "); scanf("%i",&n); if(n<1) { printf ("\nThe number should be greater than 0"); } else { a=n; //counting the digits while (a>0) { a=a/10; b++; } a=n; //adding up bth power of digits while(a>0) { sum=sum+pow(( a%10) ,b); a=a/10; } if(sum==n) printf ("\nThe number is an ARMSTRONG number"); else printf ("\nThe number is NOT an ARMSTRONG number"); } getch(); }