urgent plz help me to complete assingment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PINKA
    New Member
    • Oct 2006
    • 7

    urgent plz help me to complete assingment

    can any one explain plz urgently

    code was this
    #include<stdio. h>
    #include<conio. h>
    void main()
    {

    double a=3.1428571;
    int b=4347;
    printf("%e\t%5d \t%5.4f\t%.5f\n ",a,b,9,9);
    getch();
    }


    --------OUTPUT-------------
    3.142857e+000 4347 0.0000 0.00000
    plz explain this why is the output of this function is this
  • PINKA
    New Member
    • Oct 2006
    • 7

    #2
    urgent plz help me to complete assingment

    can any one explain plz urgently

    code was this
    #include<stdio. h>
    #include<conio. h>
    void main()
    {

    double a=3.1428571;
    int b=4347;
    printf("%e\t%5d \t%5.4f\t%.5f\n ",a,b,9,9);
    getch();
    }


    --------OUTPUT-------------
    3.142857e+000 4347 0.0000 0.00000
    plz explain this why is the output of this function is this

    Comment

    • sircool
      New Member
      • Oct 2006
      • 12

      #3
      Originally posted by PINKA
      can any one explain plz urgently

      code was this
      #include<stdio. h>
      #include<conio. h>
      void main()
      {

      double a=3.1428571;
      int b=4347;
      printf("%e\t%5d \t%5.4f\t%.5f\n ",a,b,9,9);
      getch();
      }


      --------OUTPUT-------------
      3.142857e+000 4347 0.0000 0.00000
      plz explain this why is the output of this function is this
      if you select %e formatted that means you wanna print that floating point numbers format that save memory because of floating points.
      3.142857e+000 that output means there isn't any sliding point i mean that if there is written -01 after 'e' the real number would be occur when you slide the point one time to left the following example will make clear
      3.142857e+000=0 .3142857e-01
      if the operator is '+' you need slide the dot right written times(after e)

      the following wrong is that
      printf("%e\t%5d \t%5.4f\t%.5f\n ",a,b,9,9);
      i am not sure but i think the problem is that you wrote a number that in order to object...

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by PINKA
        can any one explain plz urgently

        code was this
        #include<stdio. h>
        #include<conio. h>
        void main()
        {

        double a=3.1428571;
        int b=4347;
        printf("%e\t%5d \t%5.4f\t%.5f\n ",a,b,9,9);
        getch();
        }


        --------OUTPUT-------------
        3.142857e+000 4347 0.0000 0.00000
        plz explain this why is the output of this function is this
        it is all related to the format specifiers you are giving in the printf string, these are

        %e
        %5d
        %5.4f
        %.5f

        and you pass in for these specifiers

        double a=3.1428571;
        int b=4347;
        integer constant 9
        integer constant 9

        respectively. Taking the triples (format string, value, output)

        3.142857e+000, %e, double a=3.1428571;

        a is a floating point variable of type double with the value 3.1428571, %e indicates the printf to expect a floating point value and to print it out in exponential format therefore printf outputs 3.142857e+000

        4347, %5d, int b=4347;

        b is and integer variable with the value 4347, %5d indicates to printf to expect an int and to output it in a field of size 5 (i.e. 5 characters wide), therefore printf outputs ' 4347'.

        0.0000, %5.4f, integer constant 9

        integer constant 9 is an integer constant value 9, unfortunately %5.4f indicates to printf to expect a double value since int is normally 2 or 4 bytes and double is 8 bytes printf f consumes both the first and second integer constant 9 and interprets them as a double (this appears to have value 0 or alternatively is not representable) there printf outputs '0.0000' note it has followed the specification of 4 decimal places but ignore the specification of field with 5, it is impossible to fit 4 decimal places into a field width of 5.

        0.00000, %.5f, integer constant 9

        actually this integer constant has already been consumed by printf, at this point it is just reading random stack data it is just sheer fluke that the value is 0. %.5f indicates to printf to expect a double and print it using 5 decimal places so it outputs 0.00000

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Please don't double post

          Comment

          Working...