Question...
An approximate value of pi can be calculated usong the series given below:
Pi=4[1-1/3+1/5-1/7+1/9…+((-1)n)/(2n+1)]
((-1)n)=n is a power for-1(for your information)
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 terms in the approximation of value of pi and outputs the approximation.I ncludes a loop that allows the users to repeat this calculation for new values n until the user says she or he wants to end the program.
this coding cannot give me an output n have many error.
An approximate value of pi can be calculated usong the series given below:
Pi=4[1-1/3+1/5-1/7+1/9…+((-1)n)/(2n+1)]
((-1)n)=n is a power for-1(for your information)
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 terms in the approximation of value of pi and outputs the approximation.I ncludes a loop that allows the users to repeat this calculation for new values n until the user says she or he wants to end the program.
Code:
#include <iostream>
using namespace std;
void prime_num(int);
int main()
{
int retry;
do
{
int x = 100;
prime_num(x);
}
void prime_num( int n)
{
bool Prime=true;
for ( int k = 3; k <= n; k++)
{
for ( int j = 2; j <= n; j++)
{
if ( k!=j &&k % j == 0 )
{
Prime=false;
break; // stop looping
}
}
if (Prime)
{
cout << " do you want to repeat the process?(Yes/No)"\n";
cin >> retry;
} while ( retry='Y'|| retry='y')
cout << " Prime: " << k << "";
}
Prime = true;
}
}
Comment