Page 1 of 1

Section B: Program Testing [25 marks] 7. Is the following if statement legal in C? if (n >= 1 <=10) printf("n is between

Posted: Mon Mar 21, 2022 5:01 pm
by answerhappygod
Section B Program Testing 25 Marks 7 Is The Following If Statement Legal In C If N 1 10 Printf N Is Between 1
Section B Program Testing 25 Marks 7 Is The Following If Statement Legal In C If N 1 10 Printf N Is Between 1 (87 KiB) Viewed 62 times
Section B: Program Testing [25 marks] 7. Is the following if statement legal in C? if (n >= 1 <=10) printf("n is between 1 and 10\n"); If so, what does if do when n is equal to 0? [3] 8. Given a triangle with a base b and a height h its area is A = bxh. The following piece of C code which computes the area of a triangle contains errors. Locate the errors and show how to fix them. [5] float area_of_triangle (float base, height) float product; { product = base+height return (product/2 } 9. The following piece of code must print the number of negative values in the array Integer. Locate the errors and show how to fix them. [5] = int Integer[] = {-5,1,3,7,8,-1,-3,-7,3,10]; int i; n=0; while (n <= 10) { n += (Integer < 0)? 1:0; i; } printf("%d ", n); 4