N
N
Nika2019-03-06 20:10:55
C++ / C#
Nika, 2019-03-06 20:10:55

An exception of type 'System.StackOverflowException' was thrown. how to fix?

class Program
    {

      
        public static long Demo(int n, int x)
        { long k = 0;
            n = 1;
            int f = 0;
            if (n != f)


            k = k + (long)((Math.Pow(x, n - 1)) / (n - 1));
            n++;
            f++;
            k = Demo(n, x); 
            
            

            return k;

        }
        static void Main()
        {
            Console.WriteLine("Введите n");
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine("Введите х");
            int x = int.Parse(Console.ReadLine());
            <code></code>
            Demo(n,x);
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2019-03-06
@GavriKos

You have an infinite recursion - there is no way out of it. You call the Demo function in the Demo function without any conditions (always). How to disappear - xs, it's not clear what your program is doing.
WRAPPING THE CODE IN THE "CODE" TAG!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question