Languages-C & C Plus Plus [TCS Placement]: Sample Questions 16 - 17 of 119

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 16

C & C Plus Plus
Edit

Describe in Detail

Essay▾

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. intmain()
  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.     return0;
  10. }
  • Output:

Result: 2.000000

Result: 2.000000

Result: 1.000000

Result: 1.000000

Question 17

C & C Plus Plus

Question

MCQ▾

Which of the following problem causes an exception?

Choices

Choice (4)

a.

A syntax error

b.

Missing semicolon in statement in main ()

c.

A run-time error

d.

A problem in calling function

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.

Developed by: