Why are you giving him endless noose?

Asked

Viewed 286 times

-1

Exercise: Write an algorithm to generate and write a table with s sine values of an angle A in radians, using the series of Truncated Mac-Laurin, presented below:

A3
A5
A7
sen A = A - 6 + 120 - 5040

Conditions: the values of angles A shall vary from 0.0 to 6.3 inclusive from 0.1 in 0.1.

my code :

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

int main () {

    float A = 0.0, valor_seno;
    float aprs_tela;

    while (A <= 6.3) {
        aprs_tela = A;
        A = A - (((pow(A,3) / 6) + (pow(A,5) / 120)) - (pow(A,7) / 5040));
        valor_seno = sin(A);

        printf("O valor do seno (%.1f) com a série de Mac-Laurin é %.2f\n\n",aprs_tela ,valor_seno);

        A = A + 0.1;
    }

    return 0;
}

1 answer

1


At the beginning of the program you put that A = 0.0; (will receive 0).
Then you check whether A is < that 6,3 (Yes, for the first tie that’s true).

Then you run the line:

A = A - (((pow(A,3) / 6) + (pow(A,5) / 120)) - (pow(A,7) / 5040));

It turns out that A is equal to zero, and zero to any number is zero. In short, (((pow(A,3) / 6) + (pow(A,5) / 120)) - (pow(A,7) / 5040)) This all goes to zero.
Then you try to assign A = A - [expressao]; (That is, A (which is zero) will receive the result of the expression, which is also zero.

Then you put:

A = A + 0.1;

blz here you assign a positive value to "A".
Only a diminished value of a higher value, this will always be lower, for example: 0 - 0,1 = -0,1 (That is, the value of A will always be less than 6.3 so it is in an infinite loop).

You can understand?

  • Behold here how to format posts. There are also keyboard shortcuts, and the formatting bar in the "no mobile" version of the site, with much of the possible commands.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.