Write a C program that computes Pi with the approximation algorithm that I introduced in class. I want you to write the program in two different ways:
Put both functions into a file called pi.c. Also write a corresponding header file that has symbolic constants for both the number of LOOPS to be run as well as for the THRESHOLD value.
Finally, write a file main.c that contains the driver, which will print out pi twice calling the two different functions. I want you to call get_pi_for() first, then call get_pi_while().
I want to run the following code and give me
Code is here
home / study / engineering / computer science / computer science questions and answers / what to do write a c program that computes pi with the approximation algorithm that i introduced ...
Your question has been answered
Let us know if you got a helpful answer. Rate this answer
Question: What to do Write a C program that computes Pi with the approximation algorithm that I introduced ...
What to do
Write a C program that computes Pi with the approximation algorithm that I introduced in class. I want you to write the program in two different ways:
Put both functions into a file called pi.c. Also write a corresponding header file that has symbolic constants for both the number of LOOPS to be run as well as for the THRESHOLD value.
Finally, write a file main.c that contains the driver, which will print out pi twice calling the two different functions. I want you to call get_pi_for() first, then call get_pi_while().
What to submit
here is code but it not running correctly plz answer code file with screenshot
//compile program in following order
//Header file
//pi.h
# define threshold 0.00000000000001
float get_pi_for();
float get_pi_while();
//pi.c
# include <stdlib.h>
# include <stdio.h>
# include <limits.h>
#include"pi.h"
float get_pi_for(){
double pi = 0;
unsigned long index = 1;
double temp = 0;
while (temp - threshold)
{
temp += ((4.0/index) - (4.0/index+2));
index += 4;
}
pi = temp;
return pi;
}
float get_pi_while(){
double pi = 0;
unsigned long index = 1;
int sign = 1;
while (index < 28284277)
{
pi += 4.0/index * sign;
sign *= -1;
index += 2;
}
return pi;
}
//main.c
#include"pi.c"
int main(){
printf("Value of pi using for loop is %f\n",get_pi_for());
printf("Value of pi using while loop is
%f\n",get_pi_while());
return ;
}
Write a C program that computes Pi with the approximation algorithm that I introduced in class....
What to do Write a C program that computes Pi with the approximation algorithm that I introduced in class. I want you to write the program in two different ways: The first version will add up the first 28284277 elements of the approximation series in a simple for loop. I ask you to put the code into a function with this signature: float get_pi_for(void); The second version will break out of a while loop depending on whether a pair of...
*Write a parallel program pie.c in C or C++ (pie.cc) for Linux that computes an approximation of the number π using a series with N+1 terms.* --The series sum is partitioned in T non-overlapping partial sums, each computed by T separate child processes created with the fork() library function.* --This program demonstrates data parallelism and interprocess communication using pipes. Each child process could perform a (potentially) long computation on a separate CPU (or core). Depending on the computer architecture, the...
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...
In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read. Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. The program must be in one file. version1: use a while loop. version2: use a do-while loop. version 3: use a for loop. For each version, use a loop to...
program in C. please paste code, thanks!
CS 153 Program 4 - Stirling Approximation (separate compilation) 1. Write a pure function double factoriallint Ni that computes N! N 1023°4 ... N-1)'N Do this the obvious way by initializing a product to one and then multiplying the integers together using a loop. Zero factorial is defined to be one. Now write a pure function double atining in Ni that uses the Stirling approximation to compute: approx[e!) - V22) In this formula,...
Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and the total points. The final score should be rounded up to the nearest whole value using the ceil function in the <math> header file. You should also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by a space. If...
Selection sort is often the first sorting algorithm covered in introductory computer science courses. Java code that uses selection sort to place the elements of an integer array into non-decreasing order is shown here: public void swapNumbers(int i, int j) { int temp = numbers[i]; /* put numbers[i] somewhere to keep it safe */ numbers[i] = numbers[j]; /* put numbers[j] at index i */ numbers[j] = temp; /* put numbers[i] at index j */ } public void selectionSort(int[] numbers) {...
I need help with the code below. It is a C program, NOT C++. It can only include '.h' libraries. I believe the program is in C++, but it must be a C program. Please help. // // main.c // float_stack_class_c_9_29 // // /* Given the API for a (fixed size), floating point stack class, write the code to create a stack class (in C). */ #include #include #include #include header file to read and print the output on console...
Write a C program, containing the following functions. Function int recursive_fibonacci(int n) computes and returns the nth F(n) using recursive algorithm (i.e., recursive function call). Fibonacci numbers are defined by F(1)=F(2)=1, F(i) = F(i-1)+F(i-2), i=2,… . Function int iterative_fibonacci(int n) computes and returns the nth Fibonacci number F(n) using iterative algorithm (i.e., loop). The main function measures the memory usage and run time of iterative_fibonacci(40) and recursive_fibonacci(40), and does the comparison. To capture the execution time by millisecond, it needs...
Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...