===========================================================================
CODING
#include<all.h>
void main()
{
clrscr();
int n,m,a,b,c,i;
cout<<"Enter number for checking for Armstrong no.: ";
cin>>n;
m=n;
for(i=1,b=0,a=0;n!=0;i++)
{
a=n%10;
n=n/10;
b=a*a*a+b;
if(i==1)
cout<<"\n"<<a<<"^3";
else
cout<<" + "<<a<<"^3";
}
cout<<" = "<<b;
if(b==m)
cout<<"\n\nTherefore, "<<m<<" is Armstrong no.";
else
cout<<"\n\nTherefore, "<<m<<" is NOT an armstrong no.";
getch();
}
CODING
#include<all.h>
void main()
{
clrscr();
int n,m,a,b,c,i;
cout<<"Enter number for checking for Armstrong no.: ";
cin>>n;
m=n;
for(i=1,b=0,a=0;n!=0;i++)
{
a=n%10;
n=n/10;
b=a*a*a+b;
if(i==1)
cout<<"\n"<<a<<"^3";
else
cout<<" + "<<a<<"^3";
}
cout<<" = "<<b;
if(b==m)
cout<<"\n\nTherefore, "<<m<<" is Armstrong no.";
else
cout<<"\n\nTherefore, "<<m<<" is NOT an armstrong no.";
getch();
}
===========================================================================
No comments:
Post a Comment