Find the output\" question - while printing the produc tin teh main, it should p
ID: 3760966 • Letter: F
Question
Find the output" question - while printing the produc tin teh main, it should print the value of p, not product (there is no variable called product in the main fn). The correct statement is: cout<<"Product: "<<p;
int prod(int x, int &y, int &z) {
int product;
cout<<”Numbers before calculating product”<<x<<” “<<y<<” ”<<z<<endl;
x++;
y -= 2;
z *= 3;
product = x * y * z;
cout<<”Numbers after calculating product”<<x<<” “<<y<<” ”<<z<<endl;
return product;
}
int main() {
int a,b,c;
a= 4;
b = 5;
c = 2;
cout<<”Numbers before calling function”<<a<<” “<<b<<” ”<<c<<endl;
int p = product(a,b,c);
cout<<”Numbers after function execution”<<a<<” “<<b<<” ”<<c<<endl;
cout<<”Product “<<p;
return 0;
}
Explanation / Answer
OP:
Numbers before calling function4 5 2
Numbers before calculating product4 5 2
Numbers after calculating product5 3 6
Numbers after function execution4 3 6
Product : 90
Program:
#include<iostream>
using namespace std;
int prod(int x, int &y, int &z) {
int product;
cout<<"Numbers before calculating product"<<x<<" "<<y<<" "<<z<<endl;
x++;
y -= 2;
z *= 3;
product = x * y * z;
cout<<"Numbers after calculating product"<<x<<" "<<y<<" "<<z<<endl;
return product;
}
int main() {
int a,b,c;
a= 4;
b = 5;
c = 2;
cout<<"Numbers before calling function"<<a<<" "<<b<<" "<<c<<endl;
int p = prod(a,b,c);
cout<<"Numbers after function execution"<<a<<" "<<b<<" "<<c<<endl;
cout<<"Product : "<<p;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.