ca208t397/ts2 Marking scheme for test set2 la. O to 99 [2] b. char name[31]; c. line 4: list[10]; [1] line 6: i should start from O instead of 1 [1] line 6: semi-colons should be use instead of commas [1] line 6: i < 10 [1] line 9: semi-colons should be used instead of commas [1] line 9: jc=i instead of j>=i [1] line 10: \n should be within the double quotes. [1] line 12:missing closing brace [1] d. definition. [2] e. When a variable is the name of the array. An array name is also a pointer name.[2] f. 2a. #include <stdio.h> [0.5] int add (int,int); [1] int addl(int); [1] main( ) [0.5] { int N; [1] printf("Please add a number to start adding"); scanf("d",&N); [2] printf("`d",add(N,1)); [2] printf("`d",addl(N)); [2] return O; } int add(int n,int x) [1] { if (x<n) [1] return add(n,x+l)+x; [2] else return n; [1] } int addl(int n) [1] { if (n>1) [1] return add(n-l)+n; [2] else return 1; [1] } 3a. struct student ( [1] char name [41]; [1] char stud_no[11]; [1] struct address addr; [2] char sex; [1] float weight; [1] float height; [1] } stud; struct address{ [1] char state[41]; [1] char street[41]; [1] int houseno; [1] } b. strcpy (stud.name, "Michael J.Fox"); [1] strcpy (stud.stud_no, "nl611763"); [1] strcpy(stud.addr.state, "Chicago"); [1] strcpy(stud.addr.street, n Queens Street"); [1] stud.addr.houseno =21; [1] stud.sex = 'M'; [1] stud.weight = 65.5; [1] stud.height = 175.5; [1] 4a. Passing by reference makes use of pointers. When the numbers are swap using pass by reference, the original copy of the numbers will also be changed, Passing by value does not make use of pointers and the original copy of the numb ers will not change after swapping. [4] b. void swap(int x , int y) [2] { int temp; [1] temp = x; [1] x = yi [1] y = x; [1] } c. void swap(int *x, int *y) [2] { int temp; /*or int *temp */ [1] temp = *x; [1] *x = *y; [1] *y = temp; [1] } d. The two operators are * and &. * refers to the content of the pointer while the & refers to the address of the pointer. [4] 5a. i=O; [1] while(i<10) [1] { counter++; [1] i++; [1] } i=0; [1] do [1] { counter++; i++; [2] }while(i<10); [1] b. A for-loop is a counter loop while a while-loop is a conditional loop. A while loop can definitely replace a for-loop but a for-loop may not be able to replace a while-loop. [2] A do-while loop will execute at least once before checking the condition while the while-loop will not execute if condition is not satisfied. [2] c. switch(x) [1] case (x==10): [1] printf(nFull marks"); [1] break; [1] case (x==5): [1] printf("Just pass"); [1] break; [1] case (x < 5): [1] printf("Fail"); [1] break; [1] }