Write a program in c++ to input a number and check if it is armstrong or not
Armstrong Number : Armstrong number is a number that is equal to the sum of cubes of its digits. For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers
#include <iostream>
using namespace std;
int main()
{
int num, a, ldigit, cube = 0;
cout << "Enter A Number : ";
cin >> num;
a = num;
while (a != 0)
{
ldigit = a % 10;
cube += ldigit * ldigit * ldigit;
a /= 10;
}
if (cube == num)
cout << num << " is armstrong number ";
else
cout << num << " is not a armstrong number";
return 0;
}
OUTPUT
1.
Enter A Number : 371
371 is armstrong number
2.
Enter A Number : 476
476 is not a armstrong number
0 Comments:
Post a Comment