EmbLogic's Blog

assinment1..problem in Q-15

Q:15 Statement given: b=2.0e20+1.0;
a=b-2.0e20;
what is ’2.0e20′,?anybody executed it explain the result of ‘a’..

3 Responses to assinment1..problem in Q-15

  1. rahul.gautam says:

    it will be showing some random value….because float data type have precision till e7….after this it starts giving some random value…and in this above equation you are trying to modify 21st digit which is not possible.

  2. arjumand says:

    e20 is the scientific notation……it means 10 to the power 20

  3. rahul gaur says:

    Hi here is my code take a look ..
    I am also skeptic about the answer…

    e-notation basically 2.0e20(or AeN) represents 2.0 * 10^20..

    #include
    #include

    int main(void)
    {
    float a,b;
    b = (2.0*pow(10,20)) + 1.0;//2.0e20 Can be expressed as 2.0 * 10^20
    printf(“Value of b is %f\n”,b);

    float c = 2.0e20;
    printf(“Value of c is %f\n”,c);

    a = b – (2.0*pow(10,20))/*c*/;//if I replace the exp with var c result changes to 0.0000….
    printf(“Value of %f – %f = %f \n”,b,c,a);//Result seems lil Strange :P

    return 0;

    }

    =============output=================
    for the code in question
    [root@linuxstation asgmt]# ./fourteen
    ./fourteen
    Value of b is 200000004008175468544.000000
    Value of c is 200000004008175468544.000000
    Value of 200000004008175468544.000000 – 200000004008175468544.000000 = 4008175468544.000000

    +++++++++++++output+++++++++++++++++++
    when I replace the a = b – c ;

    [root@linuxstation asgmt]# make fourteen
    make fourteen
    cc fourteen.c -o fourteen
    [root@linuxstation asgmt]# ./fourteen
    ./fourteen
    Value of b is 200000004008175468544.000000
    Value of c is 200000004008175468544.000000
    Value of 200000004008175468544.000000 – 200000004008175468544.000000 = 0.000000
    [root@linuxstation asgmt]#

Leave a Reply to rahul.gautam Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>