Identifying Program Errors Question 7 Identify and correct the errors to produce
ID: 3914310 • Letter: I
Question
Identifying Program Errors 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) I case 1: printf("One "); printf("Two "); printf("Three "); 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] [Total for Question 7: 6 marks]Explanation / Answer
(a) To get the answer " one " you need to apply "break" statement after the end of each case.
ex: case 1 : print("one ");
Break;
(b) two get the answer 0.25 in quarter we should take the values with decimals which are eqauting and then to get the value in 2 decimals we should use "%.2f"
here %f is float and .2 is how many decimals you need to get.
double quarter=1.0/4.0;
printf("%.2f",quarter);
(c) to copy the values of an existing array into another equal size array we can use strcpy();
arrayCopy=arrayOriginal; doesn't directly support in C Langage
strcpy(arrayCopy,arrayOriginal);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.