Write the algorithm of program that evaluates the series 5-10+7+15+9- 20+11+25+... up to x terms, where the value of x is taken as input from the user. For example, the sum of the given series up to 3 terms should give 2 as output (5-10+7=2), similarly, the sum of this series up to 4 terms should give 17 as output (5-10+7+15=17), etc.
#include <iostream>
using namespace std;
int main()
{
int x;
cin>>x;
int c=1;
int e=5,o=10;
int sum=0;
for(int i=1;i<=x;i++)
{
if(i%2==0)
{
if(c==-1)
{
c=1;
}
else
{
c=-1;
}
sum=sum+o*c;
o=o+5;
}
else
{
sum=sum+e;
e=e+2;
}
}
cout<<sum;
return 0;
}
Write the algorithm of program that evaluates the series 5-10+7+15+9- 20+11+25+... up to x terms, where...
Write a program in Python that approximates the value of π by summing the terms of this series: 4/1-4/3 + 4/5- 4/7 + 4/9- 4/11 + ... The program should prompt the user for n, the number of terms to sum, and then output the sum of the first n terms of this series. Have your program subtract the approximation from the value of math. pi to see how accurate it is.
Jave eclipse Wanna help Program 1 Algorithm Problem statement: Write a Java program to add up the digits of a number entered by the user and output the result. You may not use an array top perform this task. The program should be able to handle an integer of any size. For example, if the number 1256 was entered, the sum would be: SumOfDigits = 1 + 2 + 5 + 6 = 14 Solution: The following Algorithm could be...
Python 3.6 "While Loops" Write a program that adds up a series of numbers entered by the user. The user should enter each number at the command prompt. The user will indicate that he or she is finished entering the number by entering the number 0. Example This program will sum a series of numbers. Enter the next number (enter 0 when finished) > 5 Enter the next number (enter 0 when finished) > 2 Enter the next number (enter...
Write a full C++ program Assignment4_SequenceSum that prints terms of the following mathematical sequence: ( also written as ) Your program should accept a real number from the user representing a limit, and should add and print terms of the sequence until the sum of terms meets or exceeds that limit. For example, if your user enters 2.0, program prints terms until the sum of those terms is at ≥ 2.0. You should round your answer to...
Write a matlab program to apply Horner's algorithm to evaluate the sum of the first four nonzero terms of the Taylor series for sin(x) with c=0. Your program should not use any arrays, the exponentiation operator or the factorial function. Print out your program and include the output upon execution for the special case where x = 1. How many nonzero terms of the above Taylor series are needed to guarantee that the sum approximates sin(x) to within .0001 for...
You are to write a program name expressionTree.java that evaluates an infix expression entered by the user. The expression may contain the following tokens: (1) Integer constants (a series of decimal digits). (2) One alphabetic character - "x" (representing a value to be supplied later). (3) Binary operators (+, -, *, / and % (modulo)). (4) Parentheses You will parse the input expression creating an expression tree with the tokens, then use the postOrder tree traversal algorithm to extract...
a.) Write a C++ program that calculates the value of the series
sin x and cos x, sin 2x or cos 2x where the user enters the value
of x (in degrees) and n the number of terms in the series. For
example, if n= 5, the program should calculate the sum of 5 terms
in the series for a given values of x. The program should use
switch statements to determine the choice sin x AND cos x, sin...
in C++ Extract and Add a Series of Numbers: Write a program that will extract a series of numbers (type double) from an input sentence and then add them. EXAMPLE: Suppose the sentence entered is “Give me the sum of 25.25 and 13.50. ”The program should print to the screen: The sum = 38.75 NOTE: The numbers can be of any value. Don’t hard code to the values shown in the example. In this problem take advantage of the input...
.using while loops(matlab) Write a program to display the sum of the series [ 9 + 99 + 999 + 9999 ...] Test Data : Input the number or terms :5 Expected Output : 9 99 999 9999 99999 The sum of the series = 111105
The following function computes by summing the Taylor series
expansion to n terms. Write a program to print a table of using both this function and
the exp() function from the math library, for x = 0 to 1 in steps
of 0.1. The program should ask the user what value of n to use.
(PLEASE WRITE IN PYTHON)
def taylor(x, n):
sum = 1
term = 1
for i in range(1, n):
term = term * x / i...