The best way to get the answer is to run the bubble sorting algorithm itself and turn on the counter after calling swap (). Your calculation function will (a) need almost as much as the sort itself (depending on the execution time of swap () and getprob ()) and (b) skip the point when the order of the elements changes during sorting.
Btw, swap() , - n * (n-1)/2 , ( , , ).