C Program to Draw Cosine Wave Using C Graphics

In this program, we will draw a horizontal cosine wave on screen of amplitude 50 pixels. We will use putpixel functions of graphics.h header file to color a pixel at (x, y).

C program to draw cosine wave using graphics

In this program, we first initialize graphics mode, by passing graphics driver(DETECT), default graphics mode and specifies the directory path where initgraph looks for graphics drivers (*.BGI). Then we will draw a horizontal axis using line function representing the angle in radians. Inside a for loop we calculate the value of cosine for an angle and color the specific pixel using
putpixel function. At last we increment the angle by 5.