Monday 23 May 2016

Sine wave plot implemented in C

This program is compiled using the gcc command in Linux
gcc programname.c -lm
The -lm means the mathe functions are included during compilation.

#include<stdio.h>
#include<math.h>
#define PI 3.1415926


main()
{
const increment = 15, scale = 30, centre = 40;
int angle;
int i, j;
angle = 0;
do
{
j = centre-scale*sin(angle*PI/180);
for(i=1; i<=j; i++)
printf(" ");
printf("sine\n");
angle = angle + increment;
}while(angle <= 720);
return 0;
}

No comments:

Post a Comment