Searching for "st"

Q:

We want to round off x, a Float to an Int value. The correct way to do so would be

A) Y = ( int ) ( x + 0.5 ) ; B) Y = int ( x + 0.5) ;
C) Y = ( int ) x + 0.5; D) Y = ( int ) ( ( int ) x + 0.5 )
 
Answer & Explanation Answer: A) Y = ( int ) ( x + 0.5 ) ;

Explanation:

Rounding off a value means replacing it by a nearest value that is approximately equal or smaller or greater to the given number.

 

y = (int)(x + 0.5); here x is any float value. To roundoff, we have to typecast the value of x by using (int)

 

Example:

 

#include

 

int main ()

 

{

 

  float x = 2.6;

 

  int y = (int)(x + 0.5);

 

  printf ("Result = %d\n", y );

 

  return 0;

 

}

 

Result : 3

Report Error

View Answer Report Error Discuss

Filed Under: Programming

Q:

Can you suggest any other way of writing the following expression such that 30 is used only once?

a <= 20 ? b = 30 : c = 30 ;

Answer

*( ( a <= 20 ) ? &b : &c ) = 30;

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

Q:

What would be the output of the following program?

main()

{

    static int a[20];

    int i = 0;

    a[i] = i++;

    printf ("\n%d%d%d", a[0],  a[1], i);

}

Answer

0  0  1


That's what some of the compilers would give. But some other compiler may give a different answer. The reason is, when a single expression causes the same object to be modified and then inspected the behaviour is undefined.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

Q:

Rewrite the following set of statements using conditional operators.

int a =1, b ;

if ( a > 10 )

b = 20; 

Answer

int a = 1, b , dummy;


a > 10 ? b = 20 : dummy =1;


 


Note that the following would not have worked:


a > 10 ? b = 20 : ;;


 

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

Q:

Point out the error, if any, in the following program.

main()

{

    int i = 4, j = 2;

    switch(i)

    {

     case 1 :

       printf (''\n To err is human, to forgive is against company policy.");

        break;

      case j :

       printf (''\n if you have nothing to do, don't do it here.");

       break;

    }

}

Answer

Constant expression required in the second case, we cannot use j.

Report Error

View answer Workspace Report Error Discuss

Subject: Programming

Q:

What ACH stands for?

Answer

ACH stands for Automated Clearing House, which is an electronic transfer of funds between banks or financial institutions.


 

Report Error

View answer Workspace Report Error Discuss

Subject: Bank Interview

Q:

Logical puzzle

You have 10 coins….arrange them in 4 straight lines such that each line contains 4 coins.

Report Error

View answer Workspace Report Error Discuss

Q:

Find a 10-digit number, where the first figure defines the count of zeros in this number, the second figure the count of numeral 1 in this number etc. At the end the tenth numeral character expresses the count of the numeral 9 in this number.

Answer

Sum of all numerals must be ten because each numeral stands for the count of other numerals and because this number shall have ten numerals. Beginning to choose reasonable numerals for the first figure you can come across the correct number: 6210001000.

Report Error

View answer Workspace Report Error Discuss

Subject: Number Puzzles