+ 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

4th Dec 2016, 8:16 AM
Abrar Hussain
Abrar Hussain - avatar
11 Antworten
+ 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
4th Dec 2016, 7:44 PM
Sandeep Chatterjee
+ 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; }
4th Dec 2016, 10:49 AM
Sandeep Chatterjee
+ 2
it uses pow function pow function returns Powe r as shown here
4th Dec 2016, 7:48 PM
Sandeep Chatterjee
+ 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.
5th Dec 2016, 3:44 PM
Sandeep Chatterjee
+ 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
5th Dec 2016, 3:56 PM
Sandeep Chatterjee
+ 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
4th Dec 2016, 5:34 PM
Abrar Hussain
Abrar Hussain - avatar
+ 1
@sandeep bro there is an error in defining function [error = missing terminating character]
5th Dec 2016, 12:56 PM
Abrar Hussain
Abrar Hussain - avatar
+ 1
Error in this body[ { int x; cout<<"Enter the no."; cin>>x; cout<<function(x); return 0; } ]
5th Dec 2016, 12:57 PM
Abrar Hussain
Abrar Hussain - avatar
+ 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)
5th Dec 2016, 3:48 PM
Abrar Hussain
Abrar Hussain - avatar
+ 1
@sandeep brother i find it thanks for ur support thank yoy very much
5th Dec 2016, 4:39 PM
Abrar Hussain
Abrar Hussain - avatar
+ 1
why thanks but where was the error share it I will learn it too.
5th Dec 2016, 7:02 PM
Sandeep Chatterjee