@rjrajbir, one approach is to create an MQ4 Class object which you define in the .h file and provide the class code in the .cpp file. The class would have a constructor and one function for reading the sensor which is essentially most of the code in loop() and another for getting the calculated ppm value. The constructor would be empty. The begin() class function could do the Wire.begin() and set the private or public class raw_adc and ppm variables to zero. A read_raw() function would return an int and a get_ppm() function would return a float of the last read raw value.
Using a class us the basis of a proper Arduino/Particle library so there are plenty of examples to draw from. Give it a shot and come back for help as you progress.
This example is a little “over complicated” but the idea behind is maintained
You have to add all 3 files (MQ4.ino, MQ4.cpp, MQ4.h) to your Web IDE
Please note I didn’t tested this, is compiling without any errors but I don’t have MQ4 sensor.