Question
a) The variable userChar is a char and encodrdVal is an int. What will encodedVal be for ech userChar value? switch (userChar) { case 'A':
a) The variable userChar is a char and encodrdVal is an int. What will encodedVal be for ech userChar value?
switch (userChar)
{
case 'A':
encodedVal = 1;
break;
case 'B':
encodedVal = 2;
break;
case 'C':
case 'D':
encodedVal = 4;
break;
case 'E':
encodedVal = 5;
break;
case 'F':
encodedVal = 6;
break;
default:
encodedVal = -1;
break;
}
b) If the following fragments were part of a complete program, what would they print without running the code?
1)
int x = 0;
while (++x < 3)
{
printf("%4d", x);
}
2)
int x =100;
while (x++ < 103)
{
printf("%4d ", x);
}
3)
char ch = 's';
while (ch < 'w')
{
printf("%c", ch);
ch++;
}
c) What will the following program print without running the code?
#include
int main (void)
{
int i = 0;
while (i < 3) {
switch (i++) {
case 0: printf ("fat");
case 1: printf ("hat");
case 2: printf ("cat");
defult: printf ("oh no!");
}
putchar (' ');
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started