For each of the given program segments, read the code and write the output in th
ID: 3553725 • Letter: F
Question
For each of the given program segments, read the code and write the output in the space provided below each program. For each of the given program segments, determine if there is an error in the code, circle the error in the program and write the corrected code in the space provided after each problem. It the code does not contain an error, write "no error." Note: it is possible that a program segment may contain multiple errors. The following switch statement should print x is 5, x is 10 or x is neither 5 nor 10. The following program segment should print the sum of consecutive odd and even integers between 1 and 10, inclusive. The expected output is shown below the code segment. The following program segment should print the value of x * y until either x reaches 5 or y reaches 5:Explanation / Answer
1. output : onetwothreefour
2.output : AC
3.output :
the value of x is 1
the value of x is neither 1,4, or 6
the value of x is neither 1,4, or 6
the value of x is 4
the value of x is neither 1,4, or 6
the value of x is 6
the value of x is neither 1,4, or 6
the value of x is neither 1,4, or 6
the value of x is neither 1,4, or 6
the value of x is neither 1,4, or 6
FINDING ERRORS
1. correct code :
switch(x)
{
case 5:
cout<<"x is 5 ";
break;
case 10:
cout<<"x is 10 ";
break;
default:
cout<<"x is neither 5 nor 10";
}
2. correct code :
for(int i=1,j=2; i<=10 && j<=10; i=i+2,j=j+2)
cout<<i<<"+"<<j<<"="<<i+j<<endl;
3. correct code :
int x=1;
for(int y=2; x<5 && y<5;y++)
{
cout<<x*y<<endl;
x++;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.