Welcome Guest | Sign in | Register
Switch-case - Discussion Page For Q.10625 | C Programming Questions and Answers | C Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Switch-case > Questions and Answers

Q: Rewrite the following statements using a switch statement

if( letter == 'X' )
sum = 0;
else if ( letter == 'Z' )
valid_flag = 1;
else if( letter == 'A' )
sum = 1;
else
printf("Unknown letter -->%c\n", letter );
A. Statement 1
switch( letter ) {
case 'X' : sum = 0; break;
case 'Z' : valid_flag = 1; break;
case 'A' : sum = 1; break;
default : printf( "Unknown letter -->%c\n", letter ); break;
}
B. Statement 2
switch( letter ) {
case 'X' : sum = 0;
case 'Z' : valid_flag = 1;
case 'A' : sum = 1;
default : printf( "Unknown letter -->%c\n", letter );
}
C. Statement 3
switch( letter ) {
case "X" : sum = 0; break;
case "Z" : valid_flag = 1; break;
case "A" : sum = 1; break;
default : printf( "Unknown letter -->%c\n", letter ); break;
}
D. None of these

Answer and Explanation

Answer:Statement 1
switch( letter ) {
case 'X' : sum = 0; break;
case 'Z' : valid_flag = 1; break;
case 'A' : sum = 1; break;
default : printf( "Unknown letter -->%c\n", letter ); break;
}

Explanation:
There is no explanation...

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.