ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

Compilation Error
Posted by SPAV 8 Apr 2011 19:19
Where is the mistake? Without 'sqrt' program compiled on server. On my computer all works. Why?

#include <iostream>
#include <stack>
#include <cmath>

using namespace std;

int main()
{
    long long a;
 stack<long long> s;

 while(cin>>a)
        s.push(a);

    while(!s.empty())
    {
        cout<<sqrt(s.top())<<endl;
        s.pop();
    }



}




Edited by author 08.04.2011 19:21
Re: Compilation Error
Posted by Ahmad 16 Apr 2011 17:23
You should use <iomanip> libary and use its function.

your code is good and I learn new thing from it.

you should rewrite this line of code( cout<<sqrt(s.top())<<endl;)

TO
 cout<<fixed<<setprecision (4)<<sqrt(s.top())<<endl;

Regards,
Re: Compilation Error
Posted by Hamidreza Hosseinkhani 20 May 2011 18:37
Compilation Error occured because yout main fuction must return an integer value ( 0 ).
also sqrt function argument can not be long long. change it to long double.
and use:
cout <<setiosflags( ios::fixed | ios::showpoint ) << setprecision(4) << sqrt( s.top() ) << endl;