Which of the sets of statements below will add 1 to x if x is - ProProfs Discuss
Topics
Products
Follow Us:

Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0?



A. If (x > 0) x++;else x--;
B. If (x > 0) x++;else if (x < 0) x--;
C. If (x == 0) x = 0;else x++;x--;
D. X++;x--;

This question is part of Computer Programming II Exam (Multiple Choice)
Asked by Justinsmith, Last updated: Apr 04, 2020

+ Answer
Request

2 Answers

John Adney

John Adney

Answered Dec 05, 2017

If (x > 0) x++;else if (x < 0) x--;

 

John Smith

John Smith

Answered Oct 31, 2016

If (x == 0) x = 0; else x++; x--;
 1

aliafzali

Wrong answer! 2 is true!

Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer

Email Sent
We have sent an email to your address "" with instructions to reset your password.