/* * question7.c * FINAL * BY: John Stile * Purpose: * Explain the following code fragments */ //////////////// // A - prints if a is divisable by 10, with space for other digits // 0 1 2 3 4 5 //////////////// int a // declare an int variable named 'a' // this is missing ';' at the end of line for (a=0; a<60 ; a++) // initialize a to zero // if a contains value less than 60, do block // after block execution, increment value stored in a by 1 { if ( !(a%10) ) // divide contents of a by 10, // if the remainder is 0, evaluate if() as TRUE // if the remainder is non-zero, evaluate if() as FALSE // if is TRUE, do first print // if is FALSE, do second print // Effectively, this only prints if a is divisable by 10 { printf("%D", a/10); // print the 10's places } else { printf(" "); // print a space if not divisable by 10 } } //////////////// // B - counts the number of each type of letter (irrespective of case), stores in an array. //////////////// for (i=0; line[i]; i++) // initialize i to zero // evaluate if contents of line[i] is TRUE or FALSE // if line[i] contains '\0' it is FALSE // else it is TRUE and we do block { if (!isalpha(line[i])) // if line[i] does not contains an alpha character, do block { continue; // go to next iteration of the for loop } if ( line[i] <= 'A' && line[i] <= 'Z' ) // if line[i] contains an uppercase letter, do block { c=tolower(line[i]); // assign lower case version of letter in line[i] to variable c } else { // if line[i] contains an lowercase letter, do block c = line[i]; // assign letter in line[i] to variable c } letters[ c-'a' ]++ ; // increment array element representing the number of each type of letter }