Print the values ​​of the function z = sin (x) + cos (x) that are in the interval (-0.2; 0.8) for x changing on the interval [4, -6] in increments of 0.91. Explain the task

as I understood it:

#include "stdio.h" #include "math.h" #include "iostream.h" #include "conio.h" void main() { clrscr(); float x,z; int i; for (i=-6; (i<=4) && (z>=-0.2) && (z<=0.8); i=i+0.91) { x=i; z=sin(x)+cos(x); cout <<i<<" "<<z<<" "; } getch(); } 

Only does not work :)

    2 answers 2

     double i 

    Because add to it is not a whole. On the belonging of z interval, you need to do a check in the body of the cycle, and with a successful set of circumstances, display the value.

    In general, as follows:

     for (double i = -6; i <= 4; i += 0.91) { double z = sin(i) + cos(i); if (z > -0.2 && z < 0.8) std::cout << "f(" << i << ") = " << z << std::endl; } 

      If I understood correctly, do I need to output the function values ​​in the interval (-0,2; 0,8) ? Then we need a cycle for (х) [4,-6] с шагом 0,91 . That is this:

       for( x=(-6); x<=4; x+0,91) 

      Then you count the function z=sin(x)+cos(x) , and only output what is within (-0,2; 0,8) . I emphasize that if I correctly understood the formulation of the problem!

      • I also did not quite understand the task) - Deeech
      • Roma Tyulin is also true, even he fixed the error himself) you can compile calmly)) - Zein