Home › Forums › C Programming › C program that estimates the value of the math constant e › Re: Re: C program that estimates the value of the math constant e
December 15, 2008 at 8:34 pm
#3500
GWILouisaxwzkla
Participant
cout and cin are input and output members of a stream object in the file iostream.h . This header file is associated with c++ programs and the method that most c++ programmers use for input and output. cout stands for “console output” and cin stands for console input. You can use them more easily than printf and scanf :
1 2 3 4 5 6 7 8 9 10 | <br /> <br /> int i = 1;<br /> char c = 'd';<br /> .....<br /> <br /> cout << "the int is: " << i << endl; //output : the int is: 1<br /> cout << "the char is" << c << endl; // output : the char is d<br /> <br /> |
for the program , try:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | <br /> <br /> /****************************************************************<br /> * File Name : c:programstempCG.cpp<br /> * Date : December,15,2008<br /> * Comments : new project<br /> * Compiler/Assembler :<br /> * Modifications :<br /> *<br /> *<br /> *<br /> *<br /> *<br /> * Program Shell Generated At: 3:08:27 p.m.<br /> =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /> <br /> <br /> #include <br /> //#include <br /> //#include <br /> #include <br /> //#include <br /> //#include <br /> <br /> using namespace std;<br /> <br /> //main function ******************************<br /> <br /> int main ( )<br /> {<br /> <br /> int terms;<br /> double powerOfX;<br /> double e = 1;<br /> double i = 1;<br /> double j ;<br /> double k = 2;<br /> <br /> <br /> printf ( "Enter the number of terms ( greater or equal to one ) : " );<br /> scanf ( "%i" , & terms );<br /> <br /> while ( terms > 1 )<br /> {<br /> e = e + ( 1 / i ) ;<br /> terms --;<br /> i = i * k;<br /> k ++;<br /> <br /> }<br /> printf ( "The approximated value of e : %.12lf n" , e );<br /> printf ( "The given mathematical constant e = 2.718281828459 n");<br /> printf ( "The absolute difference between the two value : " );<br /> printf ( "%.12lf n" , fabs ( 2.718281828459 - e ) );<br /> return 0 ;<br /> }<br /> <br /> <br /> <br /> |