1 / 33

EXAM 1 REVIEW!

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);

nicki
Download Presentation

EXAM 1 REVIEW!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EXAM 1 REVIEW! The Gauntlet!!!!

  2. Question 1: The following is a preprocessor directive: • int main (void) • double fct1 (double a, double b); • #define N 100 • int numbers=100;

  3. Question 2: The following demos FILE input • fscanf(stdin, “%d”, &data); • fscanf(“%d”, &data); • fprintf(fpout, “%d”, data); • fscanf(fpin, “%d”, &data);

  4. Question 3: int a; a=31%11%3; • a = 0 • a = 1.9375 • a = Divide by zero so NaN • a = 1

  5. Question 4: int b; b=14/3*3; • b = 14 • b = 12 • b = 6 • b = 1

  6. 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

  7. Question 6: Which is illegal? • int Double; • double return; • unsigned short static int x = -1; • char pause = 5;

  8. 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

  9. 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);

  10. Question 9: printf(“$$%c\t%%\t%c”,’1’,’!’); What prints? • $1%! • $1 % ! • $’1’%% ! • $$1 % !

  11. Question 10: printf(“Sum = %8.3lf”,7.8); What prints? • Sum = ▒ ▒ ▒ ▒ ▒ ▒ ▒ 7.800 • Sum = ▒ ▒ ▒ ▒ ▒ 7.800 • Sum = ▒ ▒ ▒ 7.800 • Sum = 7.800

  12. 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); }

  13. Question 12: What prints? int n=5, m; for(m=0; m<n; m++) if(m=n) printf(“m=%d”,m);

  14. Question 13: What prints? int n=5, m=0; while(--n) printf(“%d\t”,n);

  15. 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]; } }

  16. 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);}

  17. EXAM 1 REVIEW! Last person standing wins!!!

  18. Question 1: The following is a preprocessor directive: • int main (void) • double fct1 (double a, double b); • #define N 100 • int numbers=100;

  19. 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);

  20. Question 3: int a; a=31%11%3; • a = 0 • a = 1.9375 • a = Divide by zero so NaN • a = 1

  21. Question 4: int b; b=14/3*3 • b = 14 • b = 12 • b = 6 • b = 1

  22. 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

  23. Question 6: Which is illegal? • int Double; • double return; • unsigned short static int x = -1; • char pause = 5;

  24. 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

  25. 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);

  26. Question 9: printf(“$$%c\t%%\t%c”,’1’,’!’); What prints? • $1%! • $1 % ! • $’1’%% ! • $$1 % !

  27. Question 10: printf(“Sum = %8.3lf”,7.8); What prints? • Sum = ▒ ▒ ▒ ▒ ▒ ▒ ▒ 7.800 • Sum = ▒ ▒ ▒ ▒ ▒ 7.800 • Sum = ▒ ▒ ▒ 7.800 • Sum = 7.800

  28. 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

  29. Question 12: What prints? int n=5, m; for(m=0; m<n; m++) if(m=n) printf(“m=%d”,m); m=5

  30. Question 13: What prints? int n=5, m=0; while(--n) printf(“%d\t”,n); 4 3 2 1

  31. 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

  32. 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

  33. GOOD LUCK!!!

More Related