I am new to openGL
I have written the code to display a polygon on the window
after that i have tried to clear the screen using glClearColor and glClear functions
The code i have written is
I missed a line while going through your code. Disregard my previous post.
You need to clear your buffer before flush() in display().
In your display() , after you create your polygon you flush() it to render.
After your glutDisplayFunc(display); is called in main(), the buffer is empty. At next statement you are again clearing your buffer with green color. This green colored buffer is used for your next iteration where again your blue colored object is drawn.
As stated, I suggested you above as I mis-read your polygon color to be green (0,1,0) instead of (0,0,1). My idea was to just repaint everything using the same color.