TCS Papers: Sample Questions 212 - 213 of 502

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 212

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

How would you round off a value from 1.66 to 2.0?

Explanation

  • Ceil () and floor () function are used to round off a value.

  • Floor ():

  • Returns the largest integer that is smaller than or equal to x

  • Rounds down to the nearest integer

  • ceil ():

  • Returns the smallest integer greater than or equal to x

  • Rounds up to the nearest integer

  • Example:

  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5.     printf("  Result : %f" , ceil(1.44) );
  6.     printf("  Result : %f" , ceil(1.66) );
  7.     printf("  Result : %f" , floor(1.44) );
  8.     printf("  Result : %f" , floor(1.66) );
  9.     return 0;
  10. }
  • Output:

Result: 2.000000

Result: 2.000000

Result: 1.000000

Result: 1.000000

Question number: 213

» Languages » C & C Plus Plus

MCQ▾

Question

Which of the following problem causes an exception?

Choices

Choice (4) Response

a.

Missing semicolon in statement in main ()

b.

A problem in calling function

c.

A run-time error

d.

A syntax error

Answer

c.

Explanation

  • A runtime error is a program error that occurs while the program is running.

  • Other program errors include syntax errors and compile time errors.

  • Other runtime errors include- logic error, which produces the wrong output.

  • Example:

    Int a = 10, b;

    b = a/0; // infinite

    This generates runtime exception “Division by zero”.

  • To overcome the difficulty of identifying logical errors in C language exception handling was introduced in object oriented programming language.