2 write a c++ program find all amstrong numbers below 1000?
Answers
Answered by
0
#include <cmath>
using namespace std;
int main()
{
int sum, num;
cout<<"Armstrong numbers between 1 and 1000: ";
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
for(int k = 0; k < 10; k++)
{
num = i * 100 + j * 10 + k;
sum = pow(i, 3) + pow(j, 3) + pow(k, 3);
if(num == sum)
cout<<num<<" ";
}
}
}
return 0;
}
using namespace std;
int main()
{
int sum, num;
cout<<"Armstrong numbers between 1 and 1000: ";
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
for(int k = 0; k < 10; k++)
{
num = i * 100 + j * 10 + k;
sum = pow(i, 3) + pow(j, 3) + pow(k, 3);
if(num == sum)
cout<<num<<" ";
}
}
}
return 0;
}
Similar questions
Math,
7 months ago
Geography,
7 months ago
Environmental Sciences,
1 year ago
Biology,
1 year ago
Geography,
1 year ago