Section B: Program Testing [25 marks] 7. Is the following if statement legal in C? if (n >= 1 <=10) printf("n is between
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Section B: Program Testing [25 marks] 7. Is the following if statement legal in C? if (n >= 1 <=10) printf("n is between
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
Section B: Program Testing [25 marks] 7. Is the following if