Step-by-step explanation:
Enter number of terms (1-10000): 1000
Estimated value: 3.14059
Enter number of terms (1-10000): 1
Estimated value: 4
Enter number of terms (1-10000): 10000
Estimated value: 3.14149
Enter number of terms (1-10000): 100000
Error!!
Code (modify count statements)
#include <bits/stdc++,h>
using namespace std;
#define Id long double
Id pi(int n){
Id sum=0:
int sign=1;
for(int i=0;i<n;i++){
Id num= sign*1.00/(2*i+1);
sign*=-1;
sum+=num;
}
return 4*sum;
}
int main(){
int n;
count<<"----Welcome----\\";
count<<"Enter number of terms(1-1000):";
cin>>n;
while(n!=99){
if(n>10000 or n<1)
count<<"Error!!\\";
else{
count<<"Estimated value;"<<pi(n)<<endl;
count<<endl<<endl;
}
count<<"Enter number of terms(1-10000):";
cin>>n;
}
}