205k views
1 vote
What is the value of each variable after execution?

int x = 2;

int y = 7;

double p = 7.0;

int z = y / x;

double w = p / x;

z:

w:

User Alex Amato
by
5.4k points

1 Answer

4 votes

Answer:

The value of the following variable is given below:

x=2

y=7

p=7

z=3

w=3.5

Step-by-step explanation:

Following are the program in c++

#include <iostream>// header file

using namespace std; // namespace

int main() // main function

{

int x = 2; // variable declaration

int y = 7; // variable declaration

double p = 7.0; // variable declaration

int z = y / x; // variable declaration

double w = p / x; // variable declaration

cout<<" The value of following variable is given as:"<<endl<<"x:"<<x<<endl<<"y:"<<y<<endl<<"p:"<<p<<endl<<"z:"<<z<<endl<<"w:"<<w;// print all the statement

return 0;

}

Output:

x:2

y:7

p:7

z:3

w:3.5

Here the variable x is initializes by 2 ,y is initializes by 7 and p is initializes by 7.The variable z=y/x gives 3 and variable w=p/x gives 3.5 because variable w is double type

User Tom Rutchik
by
5.0k points