I have two programs that are two methods to find pi now i want to make a program
ID: 3631053 • Letter: I
Question
I have two programs that are two methods to find pinow i want to make a program to put them together
when user open run the program, the system will say which method do you want ( A or B) if incorrect, the system will say wrong order, do it again
if correct, calculate pi and then ask user do you wish to continue Y/N If N say good bye
If Y, come back to the original
Program 1:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float get_pi(int number_of_terms)
{
int count=0; //set latest estimate of pi to 0//
float i=1; //Set the denominator of the first term is 1//
float sum=0;
for (i=1; i<=number_of_terms;i+=2)
{
if(count%2==0)
sum+=(1.0/i); //It's Even Terms//
else
sum-=(1.0/i); //It's Odd Terms//
count++;
}
return sum;
}
int main()
{
int num;
printf("Please enter number of terms:");
scanf("%d",&num);
printf ("%0.6f ",4*get_pi(num)); //display the number to 6 decimal places//
return 0;
}
Program 2:
#include<stdio.h>
#include <stdlib.h>
#include<math.h>
float get_pi(float error_percentage)
{
int count=0;
float i=1.0;
float sum=0.0;
do
{
if(count%2==0)
sum=sum+(1.0/i);
else
sum=sum-(1.0/i);
count++;
i=i+2.0;
}while(4*(1.0/(i-2))>error_percentage);
return sum;
}
int main()
{
float error_percentage;
printf("Please enter error percentage you want:");
scanf("%f",&error_percentage);
printf (" value of pi is %0.100f",4.0*get_pi(error_percentage));
return 0;
}