0
using namespace std;
#include<iostream>
#include<cmath>

int main()
{
  int n;
  cin>>n;
  int temp;
  int m=0;
  for(int i=0;i<n;i++)
  {
    cin>>temp;
    m += pow(10,i)*temp;
    cout<<"\n"<<m<<"\n";
  }

  return 0;
}

OUTPUT

5

1

1

2

21

3

320

4

4320

5

54319

I wanted to get 54321 but instead got this for some reason a 1 is getting removed in the 3rd and last loop.

  • 1
    `m += pow(10,i)*temp;` Don't use floating points in integer calculations where you expect exact results. – dxiv Feb 04 '21 at 06:00
  • 1
    I switched the pow for a command I wrote myself that does the same thing and it worked. It seems like using pow from cmath causes this problem so I wanted to know why that happens. – Joelcantcode Feb 04 '21 at 06:08
  • See for example [Strange behaviour of the pow function](https://stackoverflow.com/questions/18155883/strange-behaviour-of-the-pow-function). – dxiv Feb 04 '21 at 06:11

0 Answers0