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

Visual C++ 2010, Runtime error (access violation)
Posted by Mario Pavlov 18 Mar 2014 21:03
Could someone help me ?

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    double outputNumbers[100000];
    double number;
    int index;

    index = -1;
    while (cin.fail() == false)
    {
        cin >> outputNumbers[++index];
    }

    cout << fixed;
    cout << setprecision(4);

    while (index > 0)
    {
        cout << sqrt(outputNumbers[--index]) << endl;
    }

    return 0;
}
Re: Visual C++ 2010, Runtime error (access violation)
Posted by Mario Pavlov 18 Mar 2014 22:49
I have rewrite the program, using vectors but now I receive wrong answer...

#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main()
{
    vector<double> myVector;

    double value;

    while (cin.fail() == false)
    {
        cin >> value;
        myVector.push_back(sqrt(value));
    }

    myVector.pop_back();

    cout << fixed;
    cout << setprecision(4);

    for (int i = 0; i < myVector.size(); i++)
    {
        cout << myVector[i] << endl;
    }


    return 0;
}