330 likes | 404 Views
EXAM 1 REVIEW!. The Gauntlet!!!!. Question 1: The following is a preprocessor directive:. int main (void) double fct1 (double a, double b); #define N 100 int numbers=100;. Question 2: The following demos FILE input. fscanf(stdin, “%d”, &data); fscanf(“%d”, &data);
E N D
EXAM 1 REVIEW! The Gauntlet!!!!
Question 1: The following is a preprocessor directive: • int main (void) • double fct1 (double a, double b); • #define N 100 • int numbers=100;
Question 2: The following demos FILE input • fscanf(stdin, “%d”, &data); • fscanf(“%d”, &data); • fprintf(fpout, “%d”, data); • fscanf(fpin, “%d”, &data);
Question 3: int a; a=31%11%3; • a = 0 • a = 1.9375 • a = Divide by zero so NaN • a = 1
Question 4: int b; b=14/3*3; • b = 14 • b = 12 • b = 6 • b = 1
Question 5: How many errors can you spot? int x,y; double sum; scanf(“%d %d”,x,y); x+y = sum; printf(“Sum=%d\n”, sum); None 5 2 4
Question 6: Which is illegal? • int Double; • double return; • unsigned short static int x = -1; • char pause = 5;
Question 7: Given: double x=3.0, y= 4.0, z=2.0; Which is FALSE? • x = 1.0 && x == 2.0 • x > z && y > z • x = 2.0 || y != 4.0 • z < = x && x <= y
Question 8: Which function call is valid double fct(int p, double q); //function prototype int x,y,z; double a,b,c; //declarations in main() • x = fct(x,y) • x = fct(y,a) • a = fct(b,c) • a = fct(x,a);
Question 9: printf(“$$%c\t%%\t%c”,’1’,’!’); What prints? • $1%! • $1 % ! • $’1’%% ! • $$1 % !
Question 10: printf(“Sum = %8.3lf”,7.8); What prints? • Sum = ▒ ▒ ▒ ▒ ▒ ▒ ▒ 7.800 • Sum = ▒ ▒ ▒ ▒ ▒ 7.800 • Sum = ▒ ▒ ▒ 7.800 • Sum = 7.800
Question 11: What prints? /*Section of code in main() */ int n=5, m=3; n = fct(m); printf(“n = %d m = %d\n”,n,m); /*function*/ int fct(int n) { int m = 4; return (n + m); }
Question 12: What prints? int n=5, m; for(m=0; m<n; m++) if(m=n) printf(“m=%d”,m);
Question 13: What prints? int n=5, m=0; while(--n) printf(“%d\t”,n);
Question 14: What prints? //Section in main() int n[]={5,4,3}, m[]={1, 2, 3}; fct1(3,n,m); printf(“%d %d”,m[2],n[0]); void fct1(int n, int a[], int b[]){ int j; for(j=0; j<(n-1); j++){ b[j] = b[j] - b[j+1]; a[j] = a[j] - 2*b[j]; } }
Question 15: What prints? //Section in main() int n[]={5,4,3}, m[]={1, 2, 3}; m[2] = fct1(3,n,m); printf(“%d %d”,m[2],n[0]); int fct1(int n, int a[], int b[]){ int j; for(j=0; j<(n-1); j++){ b[j] = b[j] - b[j+1]; a[j] = a[j] - 2*b[j]; } return (b[j]-1);}
EXAM 1 REVIEW! Last person standing wins!!!
Question 1: The following is a preprocessor directive: • int main (void) • double fct1 (double a, double b); • #define N 100 • int numbers=100;
Question 2: The following is an example of FILE input • fscanf(stdin, “%d”, &data); • fscanf(“%d”, &data); • fprintf(fpout, “%d”, data); • fscanf(fpin, “%d”, &data);
Question 3: int a; a=31%11%3; • a = 0 • a = 1.9375 • a = Divide by zero so NaN • a = 1
Question 4: int b; b=14/3*3 • b = 14 • b = 12 • b = 6 • b = 1
Question 5: How many errors can you spot? int x,y; double sum; scanf(“%d %d”,x,y); x+y = sum; printf(“Sum=%d\n”, sum); intx,y; double sum; scanf(“%d %d”,&x,&y); sum = x+y; printf(“Sum = %lf\n”, sum); None 5 2 4
Question 6: Which is illegal? • int Double; • double return; • unsigned short static int x = -1; • char pause = 5;
Question 7: Given: double x=3.0, y= 4.0, z=2.0; Which is FALSE? • x = 1.0 && x == 2.0 • x > z && y > z • x = 2.0 || y != 4.0 • z < = x && x <= y
Question 8: Which function call is valid double fct(int p, double q); //function prototype int x,y,z; double a,b,c; //declarations in main() • x = fct(x,y) • x = fct(y,a) • a = fct(b,c) • a = fct(x,a);
Question 9: printf(“$$%c\t%%\t%c”,’1’,’!’); What prints? • $1%! • $1 % ! • $’1’%% ! • $$1 % !
Question 10: printf(“Sum = %8.3lf”,7.8); What prints? • Sum = ▒ ▒ ▒ ▒ ▒ ▒ ▒ 7.800 • Sum = ▒ ▒ ▒ ▒ ▒ 7.800 • Sum = ▒ ▒ ▒ 7.800 • Sum = 7.800
Question 11: What prints? /*Section of code in main() */ int n=5, m=3; n = fct(m); printf(“n = %d m = %d\n”,n,m); /*function*/ int fct(int n) { int m = 4; return (n + m); } n = 7 m = 3
Question 12: What prints? int n=5, m; for(m=0; m<n; m++) if(m=n) printf(“m=%d”,m); m=5
Question 13: What prints? int n=5, m=0; while(--n) printf(“%d\t”,n); 4 3 2 1
Question 14: What prints? //Section in main() int n[]={5,4,3}, m[]={1, 2, 3}; fct1(3,n,m); printf(“%d %d”,m[2],n[0]); void fct1(int n, int a[], int b[]){ int j; for(j=0; j<(n-1); j++){ b[j] = b[j] - b[j+1]; a[j] = a[j] - 2*b[j]; } } 3 7
Question 15: What prints? //Section in main() int n[]={5,4,3}, m[]={1, 2, 3}; m[2] = fct1(3,n,m); printf(“%d %d”,m[2],m[0]); int fct1(int n, int a[], int b[]){ int j; for(j=0; j<(n-1); j++){ b[j] = b[j] - b[j+1]; a[j] = a[j] - 2*b[j]; } return (b[j]-1);} 2 -1