cs202xy login: _____________________________________________ 1. Write C code for a program that does the following. Take one integer from the command-line arguments; call the integer n. Ask the user to enter an integer n times. After each time the user types an integer, display the partial sum of all the integers typed so far. Whenever the partial sum increases by more than a /factor of 2/, also print "Woah big fella." Here is a sample transcript... ./myProgram 4 Type an integer: 3 partial sum: 3 Woah big fella. Type an integer: 2 partial sum: 5 Type an integer: 2 partial sum: 7 Type an integer: 8 partial sum: 15 Woah big fella. Grading: 2 points total. * 2/2 - correct except for perhaps one tiny syntax error * 1.5/2 - ... * 1/2 - at least one part correct (command-line arg to int, loop n times, computing sum) and nothing ridiculous * 0/2 - Common mistakes * note that argc is # of arguments, not the argument. In the example argc is 2 * note that argv[1] is a char *, so atoi(argv[1]) is the 4. * for scanf and an integer you do scanf("%d", & variableName); * for char s[100], you can do scanf("%s", s); * checking if increase by factor of 2, something like if (newSum > 2 * oldSum) ... 2. Play Computer. Keep track of the values of all the variables and what is printed on the screen. /* Final output from this: h-e-l-l-o iemlp Final output if we remove that mistake line: h-e-l-l-o ifmmp */ #include #include #include #include char s[10] = "hello"; void fun(char *s) { if (!*s) return; (*s)++; s++; // note: this was a mistake on my part. fun(s+1); } int main(int argc, char *argv[]) { int i; for(i=0; s[i] != '\0'; i++) { printf("%c-", s[i]); } printf("\n"); fun(s); printf("%s\n", s); return 0; } Grading: 2 points total * 2/2 - correct except for perhaps one tiny mistake * 1.5 - one modest mistake (e.g., having h-e-l-l-o instead of h-e-l-l-o-) * 1/2 - some parts correct (e.g., got h-e-l-l-o- part correct), nothing ridiculous * 0/2 - no part correct