I wanted to know how can I turn an analog input to output or a digital IO(without pwm)to pwm signals using arduino
You need to work on your question.
First: An analog input on arduino is "like" an voltage meter, instead of reading if the pin is HIGH (5V) or LOW (0V) it will measure the intermediate voltage.
Regarding the "without pwm IO" i think you mean "hardware PWM". Arduino have some pins that can candle hardware PWM (Arduino - AnalogWrite) and there are some libraries to use a "Software PWM" so you can use any IO (SoftPWM Library - Arduino Forum).
I think the question is how do you wanna translate between the analog value to the PWM? An example could be use a potentiometer to control a Servo like this:
Or using a potentiometer to control a led brightness.... or something else.... you need to explain what is your goal to actually help you...
Just want to turn any IO into PWM(not just dedicated pwm pinouts) life pin 36 of mega
yeah, that is typical arduino user
int number_of_points = 1024;
float duty_cycle = 0.5f;
int frequency =1;
int i = 0;
int temp = (int)number_of_points*duty_cycle;
while(1)
{
gpio_high();// Set gpio high, i don't know sintax for arduino
while(i<temp)
{
i++;
delay_us(frequency);
}
gpio_low();// Set gpio low, i don't know sintax for arduino
while(i<number_of_points)
{
i++;
delay_us(frequency);
}
i=0;
}
this is no way optimized, only to show the idea. with optimization it could make 10x higher frequency pwm signal
If you can't understand how to use that library I would say to stop what you are trying to do for some days, buy a book online (those getting started with arduino should do), and study a little bit before putting your hands on.
You will only understand and actually have some (good) questions after you study. Your question was vague and giving you a written code will not help, you need to understand what is PWM and how it works. Then you need to ask yourself why you need PWM on your project, what are you trying to do? Arduino Mega has 15 PWM iIOS, do you really need more than that? if so, shouldn't you use a dedicated IC to control what ever you are trying to control?
There are several IC's do control leds / servos that handle the PWM internally, not depending on the microcontroller hardware pwm itself.
For example, using the PCA9685 you can control 16 pwm using I2C interface. You can chain up 62 IC's to control up to 992 PWM outputs.
Adafruit has a breakout board for that chip and a lot of useful information.
I second this comment. You seem to ask a whole ton vague but basic questions on many subjects. I think you'd fair well getting an Arduino book and reading through it.
Simon Monk's books get good reviews
Amazon.com: Programming Arduino Getting Started with Sketches (9780071784221): Simon Monk: Books
I am a bit on the intermediate side and I know regarding i2C. my goal is to control almost 30-25 servos and max pwm is by mega(15) and I had to use twice as much. I never learnt I2C but know the concept. Regarding books I have a arduino cookbook and takes a while to learn(637 pages).
For servos there definitely are software pwm options as that pwm isn't fast
Just one note: to control 30 servos you will draw a fairly good amount of current, do not put all servos on arduino +5 voltage line.
If each servo draw 0.25 Amperes, 30 together will need 7.5 Amperes, way more than most of "wall mart" power supply can handle. Servos can draw easily more than .25 Amperes, depending on the load, type, etc...
I would opt to use 2 breakout boards from Adafruit if I were you, each board can be powered separately, they have example code on how to control the servo, and a very nice wiring diagram. So even not knowing anything regarding PWM and I2C you will get it working.
But, honestly, get it working and study what you are doing at the same time. 
Read this: https://learn.adafruit.com/16-channel-pwm-servo-driver
Vitor Henrique