C++ Logo

std-proposals

Advanced search

[std-proposals] Bug Report

From: Faheem Mohd Parray <parayfaheem1112_at_[hidden]>
Date: Fri, 12 Jul 2024 12:04:12 +0530
i was compiling the code and found out this error here is the code and the
output
#include <iostream>
#include <cmath>
using namespace std;

// armstrong no acb = a^3 + b^3 + c^3
int main()
{
    int n;
    cin >> n;

    int temp = n;
    int armstrong = 0;
    while (temp > 0)
    {
        int last = temp%10;
        armstrong += pow(last,3);//((temp%10)*(temp%10)*(temp%10))
        cout<< armstrong<<endl;
        temp = temp / 10;
    }

    if (armstrong == n)
    {
        cout << "Armstrong No. : " << n << endl;
    }
    else
    {
        cout << "Not an Armstrong No. : " << armstrong << endl;
    }

    return 0;
}
Output:
Armstrong_No> .\armstrong.exe
153
27
151 //here should be 125+27 =152 but its 151
152 //as the sum must be 153 but Its 152 I tried the other
as well the worked but not this
Not an Armstrong No. : 152

Received on 2024-07-12 06:34:25