/* * Assignment * Chapter 10 * By John Stile */ 1) Splain how each of the following work: 1a) printf("Test score %d: %d\n", aa,scores[aa]); ANSWER: print decimal value of variables aa and scores[aa] 1b) char fname[7]={'A','l','i','s','o','n','\0'}; ANSWER: declare and initialize character array fname with 7 elements, assigning a letter to each elment except the last, which is assigned NULL 1c) printf("\nYour name is '%s' \n", fname); ANSWER: print all elements of arraya fname as a string 1d) int main(void) { int ii; // declare int char fname[10]; // declare character array with 10 elements printf("Enter your first name: "); // prompt for input scanf("%s", fname); // read stdin as a string, // assign values to elements of array fname // add NULL at the end printf("\nYour first name is "); // print output descriptin for(ii=0; fname[ii] != '\0'; ii++) // initialize ii to 0 // if iith element is not NULL, do block // increment ii, and repeat { printf("%c", fname[ii]); // print char value of iith element of array } printf("\n"); // print newline return 0; // return 0 to calling program } 2) What line declares and initializes an array named student that contains data like the following: Natasha Mayfield Philosopy Kwakay Shu Physics ANSWER: char name[2][3][20] // 2 records,3 elements/record ,20 char/element 3) What printf line would output the S in Shu in question 2? ANSWER: printf("%c",name[1][1][0]); // 2nd record, 2nd element, first char 4) What printf line would output the string Physics? ANSWER: printf('%s",name[1][2]); // string at 2nd record, 3rd element