# Thread: Graphing a sine/cosine/tan curves in C???

1. ## Graphing a sine/cosine/tan curves in C???

http://www.sci.brooklyn.cuny.edu/~sd.../Program6.html

the link above are specifications to making a so called "simple" program, but how would this be done? especially the graphing of sin, cos and tan?

2. graph(sin,0.0,10.0,20);
You create a loop that goes from 0.0 to 10.0 (the example in the link I think got it wrong by saying 0.0 to 20.0) in increments of (hi-lo)/(num of points) so:

Code:
```void graph( double (*func)(double),double lo,double hi, int number )
{
double pt;
double inc = (hi-lo)/number;

for( pt = lo; lo <= hi; pt += inc )
{
/* Call the function for the given pt value, you would need to
do something with the return value, i.e. store it in an array perhaps
for later use */
func(pt);
}

}```
Once you've got all the values stored in an array, you need to normalize them based on the height of the screen display. Then it is a simple matter of going through the stored values in the array and outputting a symbol at the appropriate height based on the normalized value.

3. how would you print an asterisk based on the height?

4. probably create a 2d char array:-

Code:
```[ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ][ ]
[ ][ ][ ][*][ ][ ][ ]
[ ][*][*][ ][*][*][ ]
[ ][*][ ][ ][ ][*][ ]```
Then print out the 2d array using a nested for loop.

How you gets the stars into the array will be of course your main problem.