+ 1
(in c++)program using function to evaluate formula as y=(x-1/x)+1/2(x-1/x)^2+1/3(x-1/x)^3
input value x and pass to function as argument
11 odpowiedzi
+ 3
this is a loop
it is sum=0; at first run it is sum=sum+1/1*(x-1/x)^1
after that y=y+1/2*... and thus it is
y=(x-1/x)+(1/2 )* (x-1/x)^(1/2)+ (1/3)...
pow function is a function from math library that can be used to calculate power.
pow( 6, 2) is 36
+ 2
#include <iostream.h>
#include <math.h >
double function(x){
doubl i=1;
double y=0;
for(i=1; i<=3; i++){
y+= (1/i) * pow(( x-1/x ) , i);
}
return y;
}
int main(.){
int x;
cout<<"Enter the no.";
cin>>x;
cout<<function(x);
return 0;
}
+ 2
it uses pow function pow function returns Powe r as shown here
+ 2
yes it should be pow((x-1/x),i) instead of pow(x-1/x), i.) I saw it in your reply I corrected it see
if problem is even after that replace function with other word and after that check for missing } colon semicolon etc.
+ 2
ok friend no need to prove that I got it there is some error ok can you copy paste the code you are using
let us find error in it
+ 1
@sandeep its fine code! JAZAKALLAH
BUT brother can you plz tell me that how its works means
[
for(i=1; i<=3; i++){
y+= (1/i) * pow( x-1/x ) , i);
}
thanks
+ 1
@sandeep
bro there is an error in defining function [error = missing terminating character]
+ 1
Error in this body[ {
int x;
cout<<"Enter the no.";
cin>>x;
cout<<function(x);
return 0;
}
]
+ 1
bro what's ur Facebook id! I will send u photo's ! because there's no error in formula only error in bottom function(missing terminating character error)
+ 1
@sandeep
brother i find it thanks for ur support thank yoy very much
+ 1
why thanks but where was the error share it I will learn it too.