Question

For All C++ Sections /*Question:what is the output after run the following C++ code? - of int x = 12; int y = 5; if (x > y ||
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer is 24 2

The first if condition x>y is True

  • So x = x*2 = 12*2=24
  • And y = y/2 = 5/2 = 2 (int /int = int )

Code

#include<iostream>
using namespace std;

int main(){
int x=12;
int y = 5;
if(x>y || ++y < 3){
x = 2*x;
y = y/2;
cout<<x<<" "<<y<<endl;
}
else{
x = x/y;
cout<<x<<" "<<y<<endl;
}
}

Output

1 C** output.cpp X C output.cpp > main() #include<iostream> 2. using namespace std; 3 4 int main() { 5 int x=12; 6 int y = 5;

Add a comment
Know the answer?
Add Answer to:
For All C++ Sections /*Question:what is the output after run the following C++ code? - of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • My courses COMPUTER SKILLS FOR SCIENTIFIC FACULTIES All C++ Sections /*Question: what is the output after...

    My courses COMPUTER SKILLS FOR SCIENTIFIC FACULTIES All C++ Sections /*Question: what is the output after run the following c++ code? */ int x- 7; if (x 10); x = 8; if (x 7) x++; else x += 4; cout<<"x="<<x<<endl; BE Select one: O 1.x=10 O II. x=7 O III. x=12 O IV.x=8 O V.x=11 Nex age

  • A. What is the output of the following C++ code fragment? (all variables are of type...

    A. What is the output of the following C++ code fragment? (all variables are of type int) int count-1; int y-100; while (count 3) y=y-1 ; count+t cout << y << endl; cout<< count <<endl What is the value of x after control leaves the following while loop? (all variables are of type int) B. int x0 while (x < 20) sum- sum+x cout << sum<< endl;

  • Example (4) Trace the following program and find the output >> SOURCE CODE #include <iostream.h> int...

    Example (4) Trace the following program and find the output >> SOURCE CODE #include <iostream.h> int main0 // define two integers int x-3; int y = 4; //print out a message telling which is bigger if (x >y) i cout << "x is bigger than y" << endl: else cout << "x is smaller than y" << endl; return 0; Example (5) Write a C++ program that takes from the user a number in SR (Saudi Riyal) then the program...

  • What are the errors in the following code? My professor gave us this prewritten code and...

    What are the errors in the following code? My professor gave us this prewritten code and asked us to find the errors in it so that it can run properly #include <cstdlib> #include <ctime> #include <iostream> using namespace std; // input: integer // output: none // adds five to the given parameter void addFive( int x ) { x += 5; } // input: none // output: a random number int generateRandomNumber() { srand( time(0) ); return rand() % 100;...

  • What is the output of the following code snippet? (If there is some kind of syntax...

    What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice) 1.        int fly = 5; int x;        if (fly-- > 5)               x = 5;        else               x = 2;        if (x++ > 3)               cout << x;        cout << fly << endl; 2.   int i = 0;        bool b = i == 0 || i++ > 0;        if (!b)               cout << i << endl;        else               cout...

  • What does the following code output? int x = 7, y = 10; X -= 30;...

    What does the following code output? int x = 7, y = 10; X -= 30; y *= 5; X += 32; y /= 4; cout << "y = " « y << " and x = " << x << "; " << endl; X -= 10; y /= 5; cout << "x = " << x < " and y = " << y « ";" << endl;

  • Question 28 What is the output of the following program? Assume code is correct. #include <iostream>...

    Question 28 What is the output of the following program? Assume code is correct. #include <iostream> using namespace std; int main() { int i = 1,j,x = 5, y = 4; while (i <= y) { for (j = 0; j <= y2; j++) cout << 'Z'; cout << endl; i=i+1; } return 0; 3 B IV AA-I E333 X X, B, GT 12pt Paragraph

  • 12. What is the output of the following C++ code? int x; int y; int *p...

    12. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl; 13. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; x = 35; y = 46; p...

  • points): Show the output of the code below as it would appear on the monitor. int...

    points): Show the output of the code below as it would appear on the monitor. int main cout <<" <<endl: int wildcat 2: while (wildcat > 5) cout << wildcat <<endl; wildcat++ cout <K*<< endl; int jayhavk 5i do cout << jayhawk <s endl: while (jayhawk0) cout <<*" << endl; int wolverine l: while (wolverine 0 &&wolverine < 10) cout << wolverine <<endl: wolverine2: cout <<" <<endl: for (int zag-4; zag>0; zag_) cout <<****" << endl; for (int i-10; i<-30;...

  • what is the output of the following code segment? C++ g. int arr[3][4]; for (int i...

    what is the output of the following code segment? C++ g. int arr[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) arr[i][j] =i*4 + j; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) cout << arr[i][j] << " "; h. int next(int & x) { x= x + 1; return (x + 1); int main() { int y = 10;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT