C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 18)
18.
What will be the output of the following program?
#include<iostream.h>
int main()
{
float Amount;
float Calculate(float P = 5.0, int N = 2, float R = 2.0);
Amount = Calculate();
cout<< Amount << endl;
return 0;
}
float Calculate(float P, int N, float R)
{
int Year = 1;
float Sum = 1 ;
Sum = Sum * (1 + P * ++N * R);
Year = (int)(Year + Sum);
return Year;
}
Discussion:
6 comments Page 1 of 1.
Malak said:
1 decade ago
Sum = 1*(5*3*2) = 31.
Year = 1+sum = 31+1 = 32.
Year = 1+sum = 31+1 = 32.
Ivan said:
8 years ago
I think that the option D answer is wrong.
Sum = 1*(1+5.0*3*2) = 1(6*3*2) = 36.
Year = 36 + 1 = 37.
Sum = 1*(1+5.0*3*2) = 1(6*3*2) = 36.
Year = 36 + 1 = 37.
Varsha said:
7 years ago
Right @Ivan.
Bhavesh said:
6 years ago
I think the answer should be option e; because, the func should use default values which is not there bcoz, the parenthesis during func call is empty so there should be an error.
Padmaja said:
5 years ago
1*(1+5*3*2),
=1*(1+5*6),
=1*(1+30),
=31.
year=1+31=32.
=1*(1+5*6),
=1*(1+30),
=31.
year=1+31=32.
Alok said:
5 years ago
32 will be the right answer.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers