I am trying to create a solid cylinder using triangle fan.
What I’ve done so far is this:
float base = 0.5;
float height = 20;
float radius = 2.0f;
glBegin(GL_TRIANGLE_FAN);
for(float j=0; j<=height; j+=0.1)
{
glVertex3f(0,j,0);
for(int i=0; i<360; i++)
{
glVertex3f(radius*sin((float)i),j, radius*cos((float)i));
}
}
glEnd();
glPopMatrix();
The problem appears in these 3 screenshots:

As you see in all 3 screenshots there appears to be some space and not a solid cylinder.
Is that ok?
First thing you should pay attention to (Edit: I slightly misread your code. You are doing fine with the triangle fan) is that a triangle fan works like this:
For example:
Second thing is that a cylinder consists of three parts:
So the algorithm you need is:
The way you were trying to do is first, not correct, since you are not actually making a cylinder, but stacking many circles, and second is inefficient since you are filling in space that is mostly invisible (the inside of the cylinder).