Breaking

Post Top Ad

Your Ad Spot

Sunday, December 31, 2017

Scientific or Exponential Notation in C++ Language

Introduction

C++ is a very powerful Programming Language. In C++ we can develop software's, games and also develop websites. In this article we will learn that How Scientific or Exponential Notation is used for real numbers. The real numbers also written in exponential or scientific notation. This notation represents large real numbers in a short way.
        The exponential notation consists of two parts:
  • Mantissa
  • Exponent
        The general form of writing real values in exponential notation is as follows:
          ±m e ±n                              OR                             ±m E ±n
        The values before is known as mantissa and the value after e is known as exponent. Some important points about exponential notation which you must be remember are as follows:
  • Mantissa and Exponent must be positive or negative values
  • Exponent always Integer value it do not consist on Real Values
  • The absolute value of mantissa must be Greater Than of Equal To (>=) 1 and less than 10.
Examples

        Suppose we have a real number 1000.0. It can be represented in scientific notation as 1.00 x 10^3. It can also be written in exponential form as 1.0e3., In this example, 1.0 is mantissa and 3 is the value of exponent. Some examples are as follows:

        Real Number                    Scientific Notation                     Exponential Notation
        7.89                                   77.89 x 10^0                                7.89e0
        4,658,796.786                   4.658796 x 10^6                          4.658796e6
        0.00089                             8.9 x 10^-4                                   8.9e-4

Range and Precision

        The possible values that the floating variable store are described in terms of precision and range:
  • Precision: Precision is the number of digits after the decimal point.
  • Range: Range is the exponential power of 10.
        A float variable has a precision of 6 digits and a range of 10^-38 to 10^+38. Which is also used in double data type. A double has a precision of 15 digits and the range is 10^-308 to 10^+308. Double data type give more accuracy in answer instead of float.

Program:

                  #include <iostream>
                  using namespace std;
                  int main ()
                  {
                    double a,b,c;
                    a = 3.1415926534;
                    b = 2006.0;
                    c = 1.0e-10;
                    cout.precision(5);
                    cout<<a<< '\t' << b << '\t' << c << endl;
                    cout <<fixed << a << '\t' << b << '\t' << c << endl;
                    cout << scientific << a << '\t' << b << '\t' << c << endl;
                    return 0;
                  }

       Output:
                  default:
                  3.1416
                  2006
                  1e-010
                  fixed:
                  3.14159
                  2006.00000
                  0.00000
                  scientific:
                  3.14159e+000
                  2.00600e+003
                  1.00000e-010


Watch the Video:

No comments:

Post a Comment

Post Top Ad

Your Ad Spot