Question 7 Identify and correct the errors to produce the stated behaviour in th
ID: 3910210 • Letter: Q
Question
Question 7 Identify and correct the errors to produce the stated behaviour in the following C code. If code will produce the stated behaviour without modification write 'no error'. (a) This code segment should print: One int x-1; switch(x) f case 1: printf ("One "); printf ("Two "); printf ("Threeln"); case 2: case 3: [2 marks] (b) quarter should have the value 0.25 double quarter- 1/4; [2 marks] (c) Copy the values of an existing array into another equal size array arrayCopy - arrayOriginal; [2 marks]Explanation / Answer
Corrected codes:
a)
int x=1;
switch(x){
case 1:
printf("One ");
break;
case 2:
printf("Two ");
break;
case 3:
printf("Three ");
break;
}
b)
double quarter=0.25;
or double quarter=(double)1/4 because 1 and 4 are integers if we do not provide typecasting then it would display 0.
c)
int i,n;
n=sizeof(arrayOriginal)/sizeof(int);
for(int i=0;i<n;i++)
arrayCopy[i]=arrayOriginal[i];
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.