Interview Questions   Tutorials   Discussions   Programs   Videos   

C++ - Write the program form Armstrong no in c++?




298
views
asked marvit August 19, 2014 04:04 AM  

Write the program form Armstrong no in c++?


           

1 Answers



 
answered By bhjahnavi   0  
ARMSTRONG :
 Each individual number of a number is cubed and added then the sum must be equal to the given number then it is called as Armstrong.
/*program for Armstrong*/
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
void main()
{
int sum=0,n,m;
clrscr();
cout<<"enter a number";
cin>>n;
m=n;
while(n>0)
{
m=n%10;
sum=sum+(m*m*m);
n=n/10;
}
if(m==sum)
{
cout<<"the given number is amstrong";
}
else
{
cout<<"the given number is not amstrong";
}
getch();
}
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert