Open In App

ISRO | ISRO CS 2015 | Question 75

Like Article
Like
Save
Share
Report

Consider the following statements

#define hypotenuse (a, b) sqrt (a*a+b*b); 

The macro call hypotenuse(a+2,b+3);
(A) Finds the hypotenuse of a triangle with sides a+2 and b+3
(B) Finds the square root of (a+2)2 and (b+3)2
(C) Is invalid
(D) Find the square root of 3*a + 4*b + 5


Answer: (D)

Explanation:

A macro is defined with, hypotenuse (a, b) sqrt (a*a+b*b);
call hypotenuse(a+2,b+3);
hypotenuse = sqrt (a+2*a+2 + b+3*b+3)
           = sqrt (a + 2a + 2 + b + 3b + 3)
           = sqrt (3a + 4b + 5)

So, option (D) is correct.

Note: correct way to define this macro is:




#include <stdio.h>
#include <math.h>
  
//space is not allowed before bracket
#define hypotenuse(a, b) sqrt(a*a+b*b)
int main()
{
    //assume a = 1, b = 2
    printf("%f", hypotenuse (1+2, 2+3));
      
    //output should be 4.000000 
    return 0;
}



Quiz of this Question


Last Updated : 24 May, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads