C++ Programming Questions and Answers – Standard Mathematical Functions

This section on C++ interview questions and answers focuses on “Standard Mathematical Functions”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ interview questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ interview questions on “Standard Mathematical Functions” along with answers, explanations and/or solutions:

1. With which does the trigonometric functions work with angles in c++?
a) Degrees
d) Celsius

Explanation: The trigonometric functions work with angles in radians rather than degrees.

2. Which header file is required for manipulation of math functions in c++?
a) cmath
b) maths
c) math
d) dmath

Explanation: #include is a header file required for manipulation of math functions.

3. How many macros are used by mathematical functions in the header file <cerrno>?
a) 1
b) 2
c) 3
d) 4

Explanation: There are three macros used in mathematical functions. They are HUGE_VAL, EDOM, ERANGE.

4. What will be the output of the following C++ code?

1. `    #include <stdio.h>`
2. `    #include <math.h>`
3. `    int main ()`
4. `    {`
5. `        int param, result;`
6. `        int n;`
7. `        param = 8.0;`
8. `        result = frexp (param , &n);`
9. `        printf ("%d \n", param);`
10. `        return 0;`
11. `    }`

a) 6
b) 7
c) 8
d) 9

Explanation: In this program, We are breaking out the number by using the frexp function.
Output:

Note: Join free Sanfoundry classes at Telegram or Youtube
```\$ g++ math.cpp
\$ a.out
8```

5. What will be the output of the following C++ code?

1. `    #include <stdio.h>`
2. `    #include <math.h>`
3. `    int main ()`
4. `    {`
5. `        double param, result;`
6. `        param = 5.5;`
7. `        result = log (param);`
8. `        printf ("%lf", result );`
9. `        return 0;`
10. `    }`

a) 5.5
b) 3.14
c) 1.704
d) 2.4656

Explanation: In this program, We are finding out the log value of param by using param function.
Output:

```\$ g++ math1.cpp
\$ a.out
1.704748```

6. What will be the output of the following C++ code?

1. `    #include <stdio.h>`
2. `    #include <math.h>`
3. `    int main ()`
4. `    {`
5. `        printf ("%lf", pow (7.0,3));`
6. `        return 0;`
7. `    }`

a) 343
b) 343.00
c) 334
d) 324

Explanation: In this program, We are calculating the 7 power of 3 by using the powfunction. As we are using 7.0, it is producing the result in 343.00
Output:

```\$ g++ math2.cpp
\$ a.out
343.000000```

7. What will be the output of the following C++ code?

1. `    #include <stdio.h>`
2. `    #include <math.h>`
3. `    int main ()`
4. `    {`
5. `        printf ("%lf\n", fmod (5.3, 2) );`
6. `        printf ("%lf\n", fmod (18.5, 4.2) );`
7. `        return 0;`
8. `    }`

a) 1.300
b) 1.700
c)

```1.300
1.700```

d) 1.65

Explanation: In this program, We are finding the remainder of the given values by using fmod function.
Output:

```\$ g++ math3.cpp
\$ a.out
1.300000
1.700000```

8. What will be the output of the following C++ code?

1. `    #include <stdio.h>`
2. `    #include <math.h>`
3. `    int main ()`
4. `    {`
5. `        printf ("%lf", fabs (-10.6) );`
6. `        return 0;`
7. `    }`

a) 10
b) -10
c) 10.600000
d) -25

Explanation: In this program, We are finding the absolute value of -10.6 by using abs function.
Output:

```\$ g++ math4.cpp
\$ a.out
10.600000```

9. Which of the following mathematical function is overloaded in <complex> and <valarray>?
a) cos
b) tan
c) sin
d) mod

Explanation: Because tan has more different definition in normal case and in case of complex number i.e. tan = sin/cos(normally) and tan = y/x in complex numbers.

10. How many parameters are used in frexp function?
a) 1
b) 2
c) 3
d) 4

Explanation: There are two parameters that are used in frexp function. They are floating point value to be computed and pointer to an int object.

Sanfoundry Global Education & Learning Series – C++ Programming Language.

To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.