Directions: Fill in answers on the pages below. Don't spend
too much time on any one problem.
Points for each problem: 1-15, 2-15, 3-20, 4-20, 5-20, 6-20, 7-20, 8-20.
#include <stdio.h>
int main() {
}
int k;
for (k = 5; k >= 1; k--) {
printf("%i", k);
if (k != 1) printf(", ");
}
printf("\n");
1 - 1/22 + 1/32 - 1/42 + 1/52 + ... - 1/n2
Notice that the signs are alternating. Start numbering the terms with 1 and assume that n is even, so that the sign of the last (nth) term is negative. Your program segment must use a loop to calculate the sum. It must print the sum at the end.
int n = 10; /* other declarations below */ /* loop below */ /* print final sum below */
#include <stdio.h>
/* prototype here */
int main() {
double x, y;
int unitcircle;
while (1) {
scanf("%lf%lf", &x, &y);
if (x == 0 && y == 0) break;
unitcircle = circle(x, y);
printf("(%5.2f, %5.2f)", x, y);
if (unitcircle == 0)
printf(" is outside the unit circle\n");
else
printf(" is inside the unit circle\n");
}
}
/* definition of the function below */
#include <stdio.h>
int main() {
int a[] = {2, 6, 4, 7, 3, 9};
int b[] = {5, 1, 3, 2, 4, 0};
int c[6];
/* give code that will let c be the coordinate-wise sum of a and b */
/* give code to print the elements of c on one line, spaces between them */
}
#include <stdio.h>
/* prototype for function maximum here */
int main() {
int n = 4;
int a[] = {90, 98, 80, 87};
/* complete the call below */
double max = maximum(a, n);
printf("Maximum: %8.2f\n", max);
}
/* definition of maximum function here */
/* 1 */ #include <stdio.h>
/* 2 */ int main() {
/* 3 */ FILE *textfile;
/* 4 */ int score;
/* 5 */ int s[10];
/* 6 */ int n = 0;
/* 7 */ int i;
/* 8 */ textfile = fopen("source.txt", "r");
/* 9 */ if (textfile == NULL) {
/* 10 */ printf("Can't open scores.txt\n");
/* 11 */ exit(1);
/* 12 */ }
/* 13 */ for (;;) {
/* 14 */ fscanf(textfile, "%i", &score);
/* 15 */ if (score == -1) break;
/* 16 */ s[n] = score;
/* 17 */ n++;
/* 18 */ }
/* 19 */ close(textfile);
/* 20 */
/* 21 */ s[n] = 99;
/* 22 */ n++;
/* 23 */
/* 24 */ textfile = fopen("source.txt", "w");
/* 25 */ for (i = 0; i < n; i++) {
/* 26 */ fprintf(textfile, "%i ", s[i]);
/* 27 */ }
/* 28 */ fprintf(textfile, "-1\n");
/* 29 */ }
90 87 56 78 -1
what will it look like after the program has run?