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

Why Runtime error (Stack Overflow)???
Posted by Iqramul Islam 28 Oct 2018 17:22
#include <iostream>
#include <math.h>
using namespace std;

void square()
{
    long long int n;
    scanf("%lld", &n);
    if(n!=-1)
        {
            square();
            printf("%.4f\n", sqrt(n));
        }

    return;

}
int main()
{
    square();

    return 0;
}
Re: Why Runtime error (Stack Overflow)???
Posted by decay 28 Oct 2018 18:22
http://acm.timus.ru/help.aspx?topic=cpp&locale=en

Visual C++ Only. In order to increase the size of a stack and to avoid its overflow when using a “deep” recursion, you should use a special directive (in the example, the size of the stack is set to be 16 MB):

#pragma comment(linker, "/STACK:16777216")
Re: Why Runtime error (Stack Overflow)???
Posted by Iqramul Islam 30 Oct 2018 00:00
sorry i don't understand .. how to set the size of the stack??? If you can explain... it might help me.....
Re: Why Runtime error (Stack Overflow)???
Posted by decay 30 Oct 2018 12:41
#pragma comment(linker, "/STACK:16777216")

Put the line above in the very beginning of your program, that all.
Re: Why Runtime error (Stack Overflow)???
Posted by ToadMonster 31 Oct 2018 17:01
You shouldn't touch stack size at all.

You shouldn't implement algorithms with linear depth of recursion, not more then logarithmic depth.
You shouldn't place big arrays/objects on stack.
Imagine you have 1-2K stack at all.

You should get/implement stack data structure and solve problem using it.