EmbLogic's Blog

E14: Assignment 01

Dear E14 Trainees,

Update the status/issues of Assignment 01 through this post only.

26 Responses to E14: Assignment 01

  1. there is a problem in question no. 9 and question no.15
    5 questions are remaining

  2. jasmeen.kaur says:

    completed assignment 1 .Having doubt in question 9,10 and 15 … what does %g indicate?? it indicate float type of value or int type of??? in printf if we write for eg- if i is integer..and i=10;printf(“%lf”,double(i));then it will give output as 10 only…why so and why not 10.000000??

  3. Pravin bhalerao says:

    I hv a problem in questions related to “Double” data type,& Q11,Q26.

  4. Pravin bhalerao says:

    what is %.8g?

    • ayush.gupta says:

      The number 8 before g specifies the number of places which are used to display the output.

      Suppose:q=44;
      printf(“%8g\t”,q);
      printf(“%8g\n”,q);
      Its output will be:
      ——44(tab_space)——44
      replace ‘-’ by spaces) it is right justified.

      Now the dot(.) after % justifies the output towards left and it displays the output using least space.
      Suppose q=44;
      printf(“%.8g\t”,q);
      printf(“%.8g\n”,q);
      Its output will be:
      44~~~~~~44~~~~~~
      (replace “~~~~~~” by tab space of length 6 characters).
      It displays 44 justified towards left. Remember we specified 8 places (%.8g) out of which 2 places are used the rest six “~” will work as tab space of length of 6 characters.
      If say q was q=12345678 then it would have displayed 12345678 (tab_space) 12345678

      (length of normal tab space is equal to 7 characters i.e.——- ).
      Please check with Siddarth sir if i am correct.

    • ayush.gupta says:

      Correction:
      Format:%g means use %e or %f, whichever is shorter.
      An integer placed between a % sign and the format, acts as a minimum field width specifier and pads the output with spaces.
      Suppose:q=44;
      printf(“%8d\t”,q);
      ******44 (replace ‘*’ with spaces)
      the output will be display a number with a minimum of 8 characters.

      These integers placed Between % and format are called precision modifiers.
      Precision modifiers have different meanings depending on format.

      1.)When precision modifiers are used with %e, %E, and %f, the precision modifier lets you specify the number of decimal places desired. For example,
      %12.6f
      will display a floating number at least 12 digits wide, with six decimal places.
      2.) When precision modifiers are used with %g and %G, the precision modifier determines the maximum number of significant digits displayed.

      All of printf()’s output is right-justified,for left justified output you place a minus sign right after the % sign.

  5. anil says:

    1. x=y=z=-1
    ++x&&++y||++z
    output is 0 -1 0

    2. x=y=z=-1
    ++x&&++y&&++z
    output is 0 -1 -1

    3.IN QUESTION NO 12 WITHOUT OPERATOR HOW IT CAN BE POSSIBLE TO PERFORM SUBTRACTION OPERATION.

    4 IN QUESTION NO 13 HEX=%#\N WHY WE USE #?

    5 HOW WE CAN WRITE THE 10 TO THE POWER -23?

    • ayush.gupta says:

      The use of the ‘#’ character with the %x indicates that the hexadecimal number should be printed with the ’0x’ prefix.
      The use of the ‘#’ character with the %o indicates that the octal value should be displayed with a 0 prefix.

  6. Ujala Gupta says:

    Ques-7: X=Y=Z=1;
    printf(“%d”,z+=x<y?x++:y++);
    What will be answer , as it is initializing as well as comparing?

    Ques-15: float a,b;
    b=2.0e20 + 1.0;
    printf("%f\n",b);
    a=b – 2.0e20;
    printf("%f\n",a);
    its answer is beyond my expectation..?

    Ques-26…………???????

    • ayush.gupta says:

      ques-7 The ?: is a operator.
      z+=x<y?x++:y++ means
      if x<y is true then
      z=z+x++; (x will be incremented after executing the statement.)
      else x<y is false then
      z=z+y++; (y will be incremented after executing the statement.)

  7. Ques 15
    float a,b;
    b=2.0e20 + 1.0;
    printf(“%f\n”,b);
    a=b – 2.0e20;
    printf(“%f\n”,a);
    what compiler is doing internally i am unable to understand

  8. ayush.gupta says:

    float a,b,c;
    a=100/3;
    printf(“a=%f”,a); prints a=33.000000
    b=100;
    c=b/3;
    printf(“c=%f”,c); prints c=33.333332

    why are a and c giving different values when a=100/3 and also c=100/3 ?

  9. ayush.gupta says:

    Question 10
    double d=3.2;
    int y;
    x=d*(y=(int)2.9+1.1/d);
    printf(“x=%g\ty=%g\n”,(double)x,(double)y);
    after executing the above statement we get y=2 and x=6.4;
    But when I complied a new program:

    int a;
    a=(int)2.9+1.1/3.2;
    printf(“a=%g\n”,a);
    I got a=0.
    If I use “(double)a” instead of “a” in the printf statement I get a=2.
    using “(double)a” cast operator shouldn’t I get the value with decimals?
    what is the function of “(int)” in expression a=(int)2.9+1.1/3.2 and what value should it return?

  10. ayush.gupta says:

    If void has been specified with main.
    int main(void)
    Is it necessary to give return 0; statement at the end?
    Does main (void) mean that after executing, the main function will not return any value?

  11. pk8981 says:

    i am unable to understand the logics used in questions-9,10,12,15,26

  12. ayush.gupta says:

    Question 12:
    int ten=10,two=2;
    printf(“%d minus %d is %d\n”,ten,2,ten-two);
    In the printf statement if we use any integer or character (between single quotes ‘a’) in place of 2 we get output as
    10 minus 8 is 8; (if we replace 2 by integer)
    10 minus ASCII_value is 8; (if we replace 2 by character between single quotes.)
    but if we use any number with decimal values (7.28) in place of 2 we get output as:
    10 minus 8 is 10;
    can anyone explain why this happens?

  13. ayush.gupta says:

    Question 15
    float a,b;
    b=2.0e20;
    gives b=200000004008175468544.000000;
    but if I use double instead of float
    b=2.0e20;
    gives b=200000000000000000000.000000;
    why the difference?
    The float b=2.0e10; it gives b=20000000000.000000;
    but if float b=2.0e11; gives b=199999995904.000000;
    is this because of float type? but the range of float is 3.4e-38 to 3.4e+38;
    please explain.

  14. Sanjeev says:

    Q 9,10,15 stil not getting it… :(

  15. Assignment 1 completed with doubt in question 9,15 and 26.
    What is meant by %.8g?
    What is floating point underflow?

  16. 22 questions are done bt having problm in 15 que.. and last 4 quetions are remaining…

  17. Assignment 1 completed.
    Doubt in ques 9,15 & 26.
    What is meant by %.8g in ques no. 9?
    What is floating point underflow?

  18. 24 question are done but problem in question no 11&19

  19. sandesh says:

    I have completed 1st assignment.

  20. sachin says:

    I have completed assignment 1st but problem in question no 9 and 26.

Leave a Reply to Ujala Gupta 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>