Home c++ tabulation function and output output in the table

tabulation function and output output in the table

Author

Date

Category

Make a program for calculating a function using a cycle operator with a precondition. The variable x changes in step H at a given interval [a, b].

Help Find an error

# include & lt; cmath & gt;
#Include & lt; iostream & gt;
Using Namespace STD;
INT MAIN () {
 Double z, x, xn, xk, h;
 CIN & GT; & GT; xn & gt; & gt; xk & gt; & gt; h;
 While (x & lt; = xk)
  if (xn & lt; = x & lt; 0) {
   z = cos (x) * sin (x) / 2;
  }
 if (0 & lt; = x & lt; = 2 * xk / 3) {
  z = Pow (sin (x + 1), 2);
 }
 if (2 * xk / 3 & lt; x & lt; = xk) {
  z = Pow (COS (X - 1), 2);
  PrintF ("% 6.2F5S% 9.3F", X, Z);
 }
 x = x + h;
 Return 0;
}

Answer 1

Errors:

  1. The initial value of the variable x not specified
  2. While cycle contains only one function calculation. The remaining two and an increase in X occurs behind the cycle.

Here is a corrected option

# include & lt; cmath & gt;
#Include & lt; stdio.h & gt;
#Include & lt; iostream & gt;
Using Namespace STD;
INT MAIN () {
 Double z, x, xn, xk, h;
 CIN & GT; & GT; xn & gt; & gt; xk & gt; & gt; h;
 x = xn;
 While (x & lt; = xk) {
  IF (X & LT; 0)
   z = cos (x) * sin (x) / 2;
  ELSE IF (X & LT; = 2 * XK / 3)
   z = Pow (sin (x + 1), 2);
  ELSE.
   z = Pow (COS (X - 1), 2);
  PrintF ("% 6.2F% 9.3F \ n", x, z);
  x + = H;
 }
 Return 0;
}

Answer 2, Authority 200%

As I understand it, there will be another 33 copies of the same question …
Okay, they came. Beauty in the output Mouse yourself …

const doubles pi = 3.1415926;
const Double H = PI / 6.0;
Int Main (Int Argc, Const Char * Argv [])
{
  for (double x = -pi; x & lt; pi + h / 2; x + = h)
  {
    Double z = (x & lt; 0.0)? COS (X) * SIN (X) /2.0:
          (X & LT; = 2 * PI / 3)? SIN (X + 1) * SIN (X + 1):
                  cos (x-1) * cos (x-1);
    COUT & LT; & LT; "X =" & lt; & lt; x & lt; & lt; "z =" & lt; & lt; z & lt; & lt; Endl;
  }
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions