A
A
asd1237asd2021-10-12 15:51:29
C++ / C#
asd1237asd, 2021-10-12 15:51:29

How to decide if the program gives the answer in the wrong format?

#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main() {
    double a;
    int n;
    cin >> a;
    cin >> n;
    const double eps = 1e-13;
    if (a <= 0 || n == 0)
        return 0;
    if (n == 1 || a == 1.0)
        return a;
    double m, l, r;
    //  m = 0;
    if (a > 0 and a <= 1) {
        l = a;
        r = 1;
    }
    else {
        l = 1;
        r = a;
    }
    while (r - l >= eps) {
        m = (l + r) / 2.0;
        if (pow(m, n) - a > 0) {
            r = m;
        }
        else {
            l = m;
        }
    }

    cout << setprecision(12) << m;

    return 0;
}


The program should display a single number — the answer to the problem with an accuracy of at least 4 decimal places after the dot.

Examples
Input
2
2
Output
1.41421356237

The program outputs the answer in the wrong format. What are the troubles?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-10-12
@wataru

In some cases, the program does not output anything. This is hardly expected behavior.
Or the checking program waits for a newline (add "\n" after the output m).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question