Answer to Question #197925 in Electrical Engineering for mat

Question #197925

Write a program that takes the value of positive integer N and outputs the sum of the first N good numbers.


1
Expert's answer
2021-05-25T09:15:02-0400

#include <stdio.h>

#include <math.h>


int main() {

    double x, s, tn;

    int n, i;

    

    printf("Enter x: ");

    scanf("%lf", &x);

    printf("Enter n: ");

    scanf("%d", &n);

    

    /* The first term */

    tn = x;     

    s = tn;

    

    for (i=1; i<n; i++) {

        /* Next term */

        tn = -tn * x*x / (2*i) / (2*i + 1);

        s += tn;

    }

    

    printf("Approximation to sin(%f) with %d terms is %f (real value is %f)\n",

           x, n, s, sin(x));


    return 0;           

    

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS