Showing posts with label what is armstrong. Show all posts
Showing posts with label what is armstrong. Show all posts

Saturday, 30 September 2017

write a program to check number armstrong or not

C++ Program to check Armstrong number or not.

You must have basic knowledge of  C++ programming language and variable  , while loop and if..ealse and for loop

What is armstrong number?

The Armstrong number n which positive number equal to sum of cube power of individual number.It is also known as Armstrong number,

Example of armstrong number.

153=[1×1×1+5×5×5+3×3×3]  153
13=[1×1×1+3×3×3]28 is not armstrong

In this programe we must understand programming language and for loop and  if else statement. 

Example 1: Check Armstrong Number (entered by user)

#include <conio.h>
int main ( )
  int onum,reminder,sum=0,num;
cout<<"please enter the any positive number";

   //this condition is use to check num not = zero. 


   cout <<onum <<"This number is    armstrong number";


cout <<onum<<"This number is not             armstrong";

return 0;
getch ();

Please enter the any positive numer
153 This number is Armstrong

In above program ,a positive number enter by the user which value is stored in onum variable. 

After that,we copied onum into num variable

Inside the while loop , last digit is different  from num by the operation digit = num % 10;. This digit is cubed and added to the variable sum.

Now, the last digit is removed using the statement num /= 10;.

In the next cycle of while loop, second last digit is different , cubed and add into sum variable.

This simultaneous until no digits are left in num. Now, the total sum sum is compared to the original digit oum.