ISRO | ISRO CS 2015 | Question 75
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>
#define hypotenuse(a, b) sqrt(a*a+b*b)
int main()
{
printf ( "%f" , hypotenuse (1+2, 2+3));
return 0;
}
|
Quiz of this Question
Last Updated :
24 May, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...