you aren't being very clear.
what do you mean by "stops"? Does it hang? are you stuck in an infinite loop?
you said it crashed and now you say it stops.
edit:
I'm not at my home machine so I've found an online compiler.
I deleted #include <io.h> as I don't think you need it, and then when I ran it I got a segmentation fault, which means that you are probably writing over the bounds of an array.
Sorry mate. no worries.
it looks like you might be writing past the end of an array in your program.
in your for loops you could add this line of code:
cout << "value of i is " << i << endl;
(if the looping variable is i of course). And then run it. when it crashes you could examine the output to see what the value of the loop variable was just before the crash.
is there any reason you are passing by reference in your Ivedimas function?