Here is the program for sinx :

 #include(stdio.h); #include(math.h); #include(conio.h); main() { int i,j,n,m; float x,h; char z[80]; x=0; h=3.14159/24; for (i=0;i<=48;i=i+1) { x=i*h; m=40*30*sin(x); for(j=0;j<m;j=j+1) printf(" "); printf("*\n"); } getch(); } 

This program should display a sine wave in the form of "*" asterisks. Please tell me what I need to change in this program so that it tgx relative to tgx ? those. so that tangensoid is displayed instead of a sine wave.

    1 answer 1

    To solve the problem, you can implement three approaches:

    1. Go to Yandex and enter the query - "the function of calculating the tangent of C". The answer to the question is instant.

    2. Search for the definition of trigonometric functions in the built-in help IDE in which you work.

    3. Replace sin(x) in the program with sin(x)/cos(x) .

    But first you need to debug the source program. Then try to replace the sine with the cosine, make sure that everything works.

    But then you need to understand the difference between the sine function and the tangent - you do not want to look for the definition of tangent in Xi, well and good. By the way, here's another 4th option - why not just find the file math.h on your disk and see the definitions of the functions there.

    I can suggest that each function has a domain and a domain of change. In the case of a sine, the range of change is from -1 to +1. And tangent? And what is equal to the tangent pi / 2? Mechanical replacement of the sine for the tangent - will not work!

    This is how the sine plot should look (gcc, MacOSX).

     #include <stdio.h>; #include <math.h>; main() { int i,j,n,m; float x,h; char z[80]; x=0; h=3.14159/24; for (i=0;i<=48;i=i+1) { x=i*h; m=40+30*sin(x); for(j=0;j<m;j=j+1) printf(" "); printf("*\n"); } } 
    • for (j = 0; j <m; j = j + 1) -a what does this record mean? - Nikitka
    • cycle from 0 to m-1, i.e. m times in which the printf(" "); space is printed printf(" "); - alexlz
    • And why in this record: m = 40 + 30 * sin (x), are the numbers 40 and 30, and for example not 20 and 10? or are these numbers arbitrarily chosen? and generally what exactly does this record do? indicates the number of points of the graph? - Nikitka
    • Scale then y-axis. Those. sine value varies from -1 to 1, scaled to [-30; 30] and shifts by 40 so that there are no positions to the left of the beginning of the line (which is impossible). Those. the chart will occupy positions (in width) from 10 to 40 + 30 = 70 - alexlz
    • To begin with - understand the scale of the axes. - gecube