PROGRAM TO CALCULATE VALUE OF `e’

#include<stdio.h> //INCLUDING HEADER FILES
main() //MAIN() STARTS HERE
     {
          int accuracy,i,j; //VARIABLE DECLARATION
          unsigned int intpart,dec; // --DO--
          double e=1.00,term=1.00,check,temp; // --DO--
          printf("\n\nENTER THE NO OF CORRECT DECIMAL PLACES REQUIRED::"); //GETTING THE NO. OF DEC. PLACES REQUIRED
          scanf("%d",&accuracy);
          for(i=1;;i++) //CALCULATING THE VALUE OF e
               {
                    term/=i;
                    check=term;
                    for(j=1;j<=accuracy;j++)
                         check*=10;
                    intpart=check;
                    e+=term;
                    if(intpart==0)
                    break;
               }
          temp=e-2.0;
          for(j=1;j<=accuracy;j++)
               temp*=10;
          dec=temp;
          printf("VALUE OF e CORRECT TO %d DECIMAL PLACES IS 2.%d\n",accuracy,dec); //DISPLAYING THE RESULT
          printf("MINIMUM NO. OF TERMS REQUIRED = %d\n",i);
     }
Advertisements

One thought on “PROGRAM TO CALCULATE VALUE OF `e’

  1. I have been checking out your posts for the last couple of hours, and everything has been very informative and well written. I just wanted to tell you that for some reason this one doesn’t seem to work in Internet Explorer. On a side note, I was wondering if you wanted to swap blogroll links? I hope to hear from you soon!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s