C++ Programming - Functions - Discussion

Discussion Forum : Functions - Programs (Q.No. 17)
17.
What will be the output of the following program?
#include<iostream.h>
double BixFunction(double, double, double = 0, double = 0, double = 0);
int main()
{
    double d = 2.3;
    cout<< BixFunction(d, 7) << " ";
    cout<< BixFunction(d, 7, 6) << endl;
    return 0; 
}
double BixFunction(double x, double p, double q, double r, double s)
{
    return p +(q +(r + s * x)* x) * x;
}
7 20
7 19.8
7 Garbage
7 20.8
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
8 comments Page 1 of 1.

Pratishtha Kapoor said:   9 years ago
Since for first call:

Here, x = 2.3, p = 7, q = 0, r = 0, s = 0;
(r+s*x) = 0.
7 + (0 + 0 * 2.3)*2.3;
7 + 0 * 2.3.
7 + 0.
7.

For second call:

x = 2.3, p = 7, q = 6, r = 0, s = 0;
(r+s*x)=0;

Then, 7 + (6 + 0 * 2.3) * 2.3.
7 + 6 * 2.3.
7 + 13.8.
20.8.
(2)

Rahul said:   9 years ago
You are correct, Thanks @Riya.
(1)

Rajesh said:   8 years ago
Nice explanation, thank you @Pratishtha Kapoor.
(1)

Faisal said:   4 years ago
But why d=2.3?
(1)

Rajkumar said:   1 decade ago
Can anyone tell me why [D]?

Riya said:   1 decade ago
During first call x = 2.3 and p = 7, rest is 0 so (r+s*x)=(0+0*2.3) = 0.

(0)*x = (0)*2.3 = 0.

(q+0) = (0+0) = 0.

p+(0)*x = 7+(0)*2.3 = 7.

During second call x = 2.3, p = 7 and q = 6, rest is 0 so (r+s*x) = (0+0*2.3) = 0.

(0)*x = (0)*2.3 = 0.

(q+0) = (6+0) = 6.

(6)*x = (6)*2.3 = 13.8.

p = 113.8 = 20.8.

Komal said:   10 years ago
Please explain neatly.

Shweta said:   10 years ago
How the value of p = 113.8 will become 20.8 please explain?

Post your comments here:

Your comments will be displayed after verification.