I mean i know that i am accessing data outside the array but where?
You use a debugger to figure it out. Most debuggers will give you the option of setting a break condition; you can use a condition of the array index being out of range. Alternatively, you can go old school and just add debug output at strategic locations and take note of the program's current state when it bombs.
@ayush I have said you na that daniweb is the best place for your problems and see they all are helping alot. so keep update from here and ya! i have checked it solve() has problem. use a better algo to avoid that. thanks P.S (your senior :p)