c++ - Segmentation Fault In Probability Calculator -
I'm compiling it on Linux. It will compile and run, but when I enter a value for n and p, then this looks like my terminal:
7 1.0 segmentation fault (core dump)
This case In, there is input to 7 n, and input for 1.0p is in. I have tried to do it with different values. It is a thought that using dynamic programming is to fill 2D Sir potential prospects through recycling. Let me know that you need more information, but this is a complete code.
#include & lt; Iostream & gt; using namespace std; Int main (int argc, char * argv []) {int n; Double P; Cin & gt; & Gt; N; Cin & gt; & Gt; P; Cout & lt; & Lt; N; Cout & lt; & Lt; P; Cout & lt; & Lt; "Start the array."; Double ** possibility = new double * [n]; For (int i = 0; i & lt; n; ++ i) {possibility [i] = new double [n]; } // cout & lt; & Lt; "Filling Eye Loop". ;; For (int i = 0; i & lt; n; i ++) {probability [i] [0] = 0; } // cout & lt; & Lt; "Begin to fill the Joom Loop."; For (int j = 0; j and lt; n; j ++) {probability [0] [j] = 1; } // cout & lt; & Lt; "The beginning of filling the nested loop."; For (int i = 1; i
cot < & Lt; Chance [n] [n]; Probability [] [] N array is the last element probability [n-1] [n-1] , So you are running from the end of the array and implementing undefined behavior.
Comments
Post a Comment