Can you see whats wrong in this code
@akash_281 corrected the segmentation fault. but try for some cases where n and m are diff i dont think your code will give correct results
 
      
    @akash_281 corrected the segmentation fault. but try for some cases where n and m are diff i dont think your code will give correct results