Terrain from a Rectangular 2D mesh

I have the following function for creating a mesh .I want to make this mesh into 3D terrain.What additions should be make in the following code.I want to create Height fields from this rectangular mesh.How to do that.

void DrawMesh(GLfloat size, GLint Linesx, GLint Linesz)
{
glBegin(GL_LINES);
for (int xc = 0; xc < LinesX; xc++)
{
glVertex3f( -size / 2.0 + xc / (GLfloat)(LinesX-1)*size,
0.0,
size / 2.0);
glVertex3f( -size / 2.0 + xc / (GLfloat)(LinesX-1)*size,
0.0,
size / -2.0);
}
for (int zc = 0; zc < LinesX; zc++)
{
glVertex3f( size / 2.0,
0.0,
-size / 2.0 + zc / (GLfloat)(LinesZ-1)*size);
glVertex3f( size / -2.0,
0.0,
-size / 2.0 + zc / (GLfloat)(LinesZ-1)*size);
}
glEnd();
}

Regards

I avoid code dumps from other people like the plague however, some at-first-glance-hints

1- Use vertex arrays. Compute once and reuse.
2- “/ 2.0” is evil: “* .5f” is much better.
3- My terrain renderers does not have constants in them. Do you really need?

How to turn a mesh in a terrain?
Depending on how much “elegant”, “nice”, “fast”, “portable” your code is meant to be there may be different apporoaches.

What you are probably asking is to do a brute-force renderer. In that case, you just have to create WxH vertices for a WxH heightmap. Then, look pixel (w,h) from the image and put its value (after adeguate processing) in vertex (w, h), Y coordinate.
If you want to just code fast you can do it in less than a week. If you want to have something elegant, it may take longer. If you want it to be fast it will take much longer.