can you please help me with modifying the second sketch.
I could, but I think that it is important that you review both sketches to understand what they are doing.
The second sketch currently does something. Compare what you see happening with the code, and make sure that you understand what bits of code make that happen.
The first sketch has a block of code that gets data from the ping sensor, and prints some data to the serial port. Make sure you understand which bits of code are getting the data, and which bits are printing it to the serial port.
When you understand both sketches, you will see that it is easy to copy the code to get data from the ping sensor from one sketch to the other. Sending data to the LCD instead of the serial port is trivial