Code written for my Mtech project . Originally wriiten in C. Will write in C++ too