Write a C++ program using a while loop to calculate the value of pi/2 accurate to 6 digits after the decimal point using the following series:
DIsplay the following and turn in printouts of the program and the results:
The number of terms needed to find pi/2
THe value of pi/2 using acos(-1.0)/2 using 10 digits after the deciaml point
The value of pi/2 found with the series using 10 digits after the decimal points (The first 6 digits after the decimal point sohuld match the value above.)
#include <iostream>
#include <cmath>
using namespace std;
const double pi = 3.141592653589793238462643383;//actual value of
PI
int main()
{
int num_accuracy=6;//accuracy for 6 digits
double x = 1.0;//initial value of x
int i = 0;//number of terms without counting the first term
double curr = 1.0;
while(1)
{
i++;//increasing number of terms
curr = curr*i/(2*i+1);//summation term for each iteration
x = x + curr;
if(fabs(x-pi/2.0)<pow(10.0,-1*num_accuracy))//checking if
value is in error range
break;
else continue;
}
printf("Value of pi upto accurate upto 6 digits: %.12f\n",
x);
cout << "Number of terms: " << i+1 << endl;//i+1
by including the first term
double pi_exact = acos(-1.0)/2;//value of pi calculated using
acos
printf("Value of pi using acos: %.12f\n", pi_exact);
num_accuracy = 10;//for accuracy upto 10 digits
x = 1.0;
i = 0;
curr = 1.0;
while(1)
{
i++;
curr = curr*i/(2*i+1);
x = x + curr;
if(fabs(x-pi/2.0)<pow(10.0,-1*num_accuracy))//checking if value
is in error range
break;
else continue;
}
printf("Value of pi upto accurate upto 6 digits: %.12f\n",
x);
cout << "Number of terms: " << i +1<< endl;
}
Sample output:
.
Please give this solution a thumbs up if you find it helpful and comment if you have any doubts in it. I would be happy to help you. Thank you.
Write a C++ program using a while loop to calculate the value of pi/2 accurate to...
Write a c++ program to calculate the approximate value of pi using this series. The program takes an input n that determines the number of values we are going to use in this series. Then output the approximation of the value of pi. The more values in the series, the more accurate the data. Note 5 terms isn’t nearly enough. You will try it with numbers read in from a file. to see the accuracy increase. Use a for loop...
c++ ( while loop ) Write program to find and display the value of the function y ,given as following : y = 15x3 + √2x − 3, for the values of x in between 2 and 10, with an increment of 1.
Write a C++ program. Using the while loop or the do – while loop write a program that does the following: Calculate the average of a series of homework grades (0 - 100) entered one at a time. In this case the lowest score will be dropped and the average computed with the remaining grades. For example suppose you enter the following grades: 78, 85, 81, 90, 88, 93 and 97.The average will be computed from the 6 grades 85,...
The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...
need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...
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...
Assignnment #1 Your Very First C++ Program Write a C+program to achieve the followings. Start a new line for each output a. Declare an integer and assign it with a value 45876 b. Prompt the user to input a floating point number of value 345.24681359 Display the message "Welcome to the 2019 EECE 4272 Summer Class!" c. d. Display the number from part (a) with the following format: () fixed floating-point number, (i) 2 digits after the decimal point, (ii...
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...
*In C language *Without using Strings Write a program that uses a for loop to calculate the average cost of a dinner for a group of 10 people. Your program will use a function that will ask the user to enter in the price of each meal and return the value entered. Your program will calculate the total due for all 10 meals, the total tip using a defined constant of 20%, and the average price of a dinner. You...