C++
Which of the following is a correct way to ensure that once we read a nonnegative value into x, the loop will stop?
(1)
int x;while(x <>cin >> x;if(x <>cout < “x="" must="" be="">=0”;}
(2)
int x;for(cin >> x ; x < 0="">cin >> x;cout < “x="" must="" be="">=0”;
(3)
int x;do{cin >> x;if(x <>cout < “x="" must="" be="">=0”;}
(4)
int x;cin >> x;while(x <>cin >> x;cout < “x="" must="" be="">=0”;}
Choices:
a. 2 and 4
b. 3 and 4
c. 2 and 3
d. 1 and 3
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here