Question

The Taylor expansion of the function sin(x) around the point x 0 is given by: sinCrx35 sin(x) = χ--+ +-.. Write a C+program t

Without the use of array, classes etc. Only allowed to use for loop, while, else, if else etc

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Ive used simple while loops. nothinq else

#include <iostream>
using namespace std;

int main() {
    double x = 0;
    while (x != -1) {
        cout << "Enter a value for x(close to 0) and -1 to exit: ";
        cin >> x;
        if (x != -1) {
            double total = 0, term = 1, power = x, factorial = 1;
            int sign = 1, i = 1;
            while (term > 10e-7) {
                term = power / factorial;
                total += sign * term;
                sign *= -1;
                power *= x*x;
                factorial *= (i+1)*(i+2);
                i += 2;
            }
            cout << "sin(" << x << ") is " << total << endl;
        }
    }
    return 0;
}

Enter a value for x (close t。0) and-1 t。exit: sin (0.1) is 0.0998334 Enter a value for x(close to 0) and -1 to exit: sin (0.5

Add a comment
Know the answer?
Add Answer to:
Without the use of array, classes etc. Only allowed to use for loop, while, else, if...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Objectives: Use the while loop in a program Use the do-while loop in a second program...

    Objectives: Use the while loop in a program Use the do-while loop in a second program Use the for loop in a third program Instructions: Part A. Code a for loop to print the Celsius temperatures for Fahrenheit temperatures 25 to 125. C = 5/9(F – 32).Output should be in a table format: Fahrenheit Celsius 25 ? . . . . . . . . Turn in the source and the output from Part A. Part B. Code a while...

  • Problem 5 xx The Taylor series expansion for sin(x) is sin(x) = x -H + E-E+...

    Problem 5 xx The Taylor series expansion for sin(x) is sin(x) = x -H + E-E+ = o E- (-1) . 2n +1 no (2n+1)! !57 where x is in radians. Write a MATLAB program that determines sin(x) using the Taylor series expansion. The program asks the user to type a value for an angle in degrees. Then the program uses a while loop for adding the terms of the Taylor series. If an n is the nth term in...

  • c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc..   Please...

    c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc..   Please do all parts. previously I post 3 time for part1 ,2 and 3 but I can't make it into one complete program code. I even try to post a questions ask and post the 3 parts of code for experts to put it together. But experts said it's not enough information. please help... Thank you ! Program Objectives: Allow students to create arrays Allow...

  • I should use the array and loop to create a java program according to the instruction,...

    I should use the array and loop to create a java program according to the instruction, but I have no idea how to do it. Introduction This lab assignment continues to give you practice using loops, particularly loops with variable termination conditions, and it also provides you an opportunity to use one-dimensional arrays. Recall that an array is used to store a collection of data. The data can be values of Java primitive data types or else objects (for instance,...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. DON'T use Function concept or any other concept except while loop,if-else. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly...

  • in java / You will: // 1- create a square 2 dimensional array of random size...

    in java / You will: // 1- create a square 2 dimensional array of random size (less than 11) // 2- fill the array with random integers from 1 to the size limit // 3- print the array // 4- prompt to see if the user wants to do another //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // 1- The square can use the same random value for x and y. Don't allow 0 size arrays. // 2- Maybe a nested set of for loops? to...

  • Use only if else nested if else only otherwise your answer won't be entertained. Problem 1(b):...

    Use only if else nested if else only otherwise your answer won't be entertained. Problem 1(b): Write a program that gives remainder without using modulus operator and loops. The first number entered will be dividend and second number entered will be divisor. Sample input: 15 6 Sample output: Remainder is 3 In a right triangle, the square of the length of one side is equal to the sum of the squares of the length of the other two sides. Write...

  • Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring...

    Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...

  • Hi, this is an intro to C Programming Class. Please do not use arrays, functions, math.h,...

    Hi, this is an intro to C Programming Class. Please do not use arrays, functions, math.h, or struct to store any data except to declare strings char strVar[20]. Furthermore, can you please do a good check to make sure the final program does not have any problems because when I copy and paste them the app I use says there are some problems and it won't run the program. So if you can double check to make sure that everything...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT