-
guys this is running but i need to give the value for the count.which i dont want to happen.Plzzzzzzzzzzzz look at it
Code:
#include <iostream>
#include<cmath>
using namespace std;
int zahl( double , double x[], double );
int main (void)
{
int ncount=10,i;
double a[ncount];
double subject,epsilon,newepsilon;//,newepsilon;
cout<<"Please input a postive real number:";
cin>>subject;
cout<<"Please input a postive real value for the relative accuracy epsilon:";
cin>>epsilon;
ncount = zahl (subject, a, epsilon);
// cout<<"count="<<ncount<<endl;
double x[ncount];
x[0]=subject/2.0;
cout<<"Value\t\tRelative Accuracy"<<endl;
cout<<"x[0]="<<x[0]<<endl;
for(i=0;i<ncount;i++)
{
x[i+1]=((x[i] +(subject/x[i]))/2.0);
newepsilon=((x[i+1]-x[i])/x[i+1]);
cout<<"x["<<i+1<<"]="<<x[i+1]<<"\t\t"<<abs(newepsilon)<<endl;
}
}
int zahl ( double subject,double x[], double epsilon)
{
x[0]=subject/2.0;
int n=0;
double newepsilon;
x[n+1]=((x[n] +(subject/x[n]))/2);
newepsilon=((x[n+1]-x[n])/x[n+1]);
int count=10;
while(newepsilon > epsilon)
{
x[n+1]=((x[n] +(subject/x[n]))/2);
newepsilon=((x[n+1]-x[n])/x[n+1]);
newepsilon=abs(newepsilon);
count=count+1;
}
return count;
}
-
Yes it is.If you want not to set it manually you can read it from stdin, with cin and then declare the array. Why you are not happy with the code ?:)
-
You still need to fix your indentation.