Sunday 9 September 2018

Program to check whether a Number is Armstrong number or not

This lrograp help you to understand the basic concept of Armstrong number.

A number said to be Armstrong if its all base value's cube is equal  to the number itself

For example

In this case we took 371

So 3^3+7^3+1^3=27+343+1
Equal to 371

So program


#include<iostream>
#include<math.h>
using namespace std;
int main(){
int num=371,rem,tempnum=0,hold;
while(num>0){

rem=num%10;
hold=(int)(pow(rem,3)+0.5);
num=num/10;
tempnum=tempnum+hold;
}
if(tempnum==num){
cout<<"YES";
}
else{
cout<<"NO";
}
return 0;
}

Note** Here one this you must know is that you have to cast the pow() function as it only takes double as an argument so we have to cast it with Int type and add 0.5 to get absolute value


Working of program

1. When num = 371 with % we can find the remainder which is 1
2. Store 1 is rem variable
3.hold is to find the cube of a number
4.Now we have to decrease value of num by one's decimal point so now num is 37
5. A temp variable has been used to store the hold value
6 . Repeat the process untill the value of num reached to 0 or below


Program to check whether a Number is Armstrong number or not

This lrograp help you to understand the basic concept of Armstrong number. A number said to be Armstrong if its all base value's cube...

Popular Posts

Copyright ©


This site is reserved to copyright.if anyone is using our content without our permission.he will face legal advisory. ©