C - Show Trigonometry cosine wave

Description

Show Trigonometry cosine wave

Demo

#include <stdio.h>
#include <math.h>

#define PI 3.14159//from www.j  ava  2  s .co m
#define WAVELENGTH 35
#define PERIOD .1

int main()
{
    float graph,s,x;

    for(graph=0;graph<2*PI;graph+=PERIOD)
    {
        s = cos(graph);
        s+=1.0;         /* compensate for negative values */
        for(x=0;x<s*WAVELENGTH;x++)
            putchar('*');
        putchar('\n');
    }
    return(0);
}

Result

Related Topic