Â
In this, we are going to see while loop, the program is based on while loop which verifies, Armstrong numbers Example:- 153 = 1*1*1 + 5*5*5 + 3*3*3Â
-->153 is an Armstrong number..
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
c=0;
cout<<"Enter number you want to check for armstrong number"<<endl;
cin>>a;
b=a;
while(b!=0)
{
d=b%10;
c=c+(d*d*d);
b=b/10;
}
if(c==a)
{
cout<<"The number is Armstrong number";
}
else
cout<<"The number is not an Armstrong number";
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d;
c=0;
cout<<"Enter number you want to check for armstrong number"<<endl;
cin>>a;
b=a;
while(b!=0)
{
d=b%10;
c=c+(d*d*d);
b=b/10;
}
if(c==a)
{
cout<<"The number is Armstrong number";
}
else
cout<<"The number is not an Armstrong number";
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP