暨南大学C语言样题

  • 格式:doc
  • 大小:58.50 KB
  • 文档页数:6

. .. . .I.True/False1.( F)Identifiers consist of letters and digits in any order, but must be in lowercase.2.(T)We create modular programs because they are easier to develop, correct andmodify.3.(F)All computers use twice the amount of storage for double precision than floatingpoint data type4.(F)Static variable is not created and destroyed each time the function is called, it is thedefault storage class used by C.5.(T)A compound statement may be used anywhere in C program in place of a singlestatement.6.(F)In C language, all operators are binary operator which connecting tow operandsside-by-side.7.(T)The Escape Sequence is a combinations of a backslash (\) and a character that tellsthe compiles to escape from the ways these character would be normally interpreted8.(T)Extern storage class is to extend the scope of a global variable beyond its normalboundary-file. it does not cause the creation of a new variable.9.(F)After defined, the symbolic names can be used in any statement and the programcan change the value of the symbolic names.10.(T)The mistake of u sing the assignment operator”=” in place of the relationaloperator”==” results in a invalid C expressionII.Choice11.(C)For the algebraic expression 3ae/bc, which of the following C expression is invalidA) a/b/c*e*3 B) 3*a*e/b/cC) 3*a*e/b*c D) a*e/c/b*312.(D)For the declarations: char w; int x; float y; double z; the data type of the value ofw*x+z-y isA) float B) charC) int D) double13.(B)For following declaration, which expression will not result in 3 ?int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, *p1 ;A) x[3] B) p1 = x +3, *p1++C) p1 = x +2, *( p1++ ) D) p1 = x +2, *++p114.(A)Which one is not endless loop?A) for (y = 0, x = 1 ; x > ++y ; x = i++ ) i = x ;B) for ( ; ; x ++ = i ) ;C) while (1) {x ++;}D) for ( i =10 ; ; i--) sum += i ;15.(B)The result of the following program ismain(){ int a = -2, bdo{ b = ++a;if (!b) printf(“#”);else printf(“*”);}while(a<1)}A}#*# B} *#*C)### D) ***16.(D)Which one of the following functions is valid ?A) double fun ( int x , int y ){ z = x + y ; return z ;}B) fun ( int x , y ){ int z ;return z ;}C) fun ( x , y ){ int x ,y ; double z ;z = x + y ; return z ;}D) double fun ( int x , int y ){ double z ;z = x + y ; return z ;}17.(D)In a source codes file of C language, if a variable can only be used by all functionswith the file itself, the storage class of the variable isA) extern B) registerC) auto D) static18.(B)The C programming language the symbol “= =”isA) rational operator B) logical operatorC) conditional operator D) assignment operator19.(D)For the definition statement: double s = 123.5; , which one is the correct outputstatement?A) printf(“s=%d ”, s); B) printf(“s=%ld ”, s);C) printf(“s=%f ”, s); D) printf(“s=%lf ”, s);20.( C)Which of the following expressions will result in 0?A) 3%5 B) 3/5.0C) 3>5 D) 3<5III.F ill in the blanks in each program to implement the purpose according to the descriptionDescription#1:The following program can accept elements of an array from the keyboard, andfind the maximum element and corresponding index in the array.main(){ int x[10], *p1, *p2, k;for(k = 0; k < 10; k++) scanf("%d", x+k);for(p1 = x, p2 = x; p1-x < 10; p1++ )if(*p1 > * p2) p2 = 【21】 ;printf("MAX = %d, INDEX = %d\n", *p2,【22】);}21.A) p1 B) p2[p1] C) x[p2] D) x – p122.A) p1– x B) p1 C) p2 – x D) x – p2Description#2: For each x, the program will calculate a corresponding y according to themain(){ int x, y;scanf(“%d”, &x);if(【23】 ) y = x * (x + 2);else if(【24】 ) y = 2 * x;else if(x <= -1) y = x - 1;else 【25】;if(y != -1) printf("%d", y);else printf("error");}23.A) x > 2 | | x <= 10 B) x > 2 && x <= 10C) x < 2 && x <= 10 D) x < 2 | | x >= 1024.A) x < -1 | | x >= 2 B) x > -1 | | x <= 2C) x > -1 && x <= 2 D) x > -1 ^ ^ x <= 225.A) y = -1 B) y = 0 C) x = 0 D) x = -1IV.(1)What is the purpose of the following program?#include<stdio.h>#define N 10main(){int t, i, j, a[N+1] ;printf(“please input 10 integers:”);for (i=1; i<=N; i++)scanf(“%d”, &a[i]);printf(“\n”);for (i=1; i<=N-1; i++){ for (j=1; j<=N-i; j++)if (a[j]<a[j+1]){t=a[j+1]; a[j+1]=a[j]; a[j]=t;}}for (i=1; i<=N; i++) printf(“%d”, a[i]);printf(“\”n);}从大到小排列数字。

(2)Read the grogram and guess the result of the program#include <stdio.h>int k = 1;char a[ ] = “IBM computer”, b[ ] = “C program”;int fuc();main(){ int p = 3;while (putchar(a[k])) k++; /*k=12*/putchar(‘\n’);printf(“k=%d, ”, k);k=fuc(p);printf(“%d, %d\n”, p,k);printf(“%c%s\n”, a[0], &b[p]);puts(&a[3]);}int fuc(int m){int k = 0;while (putchar(b[k])) k++;printf("k=%d\n", k);k +=m; m *=k;printf("%d, %d\n", m, k);return (m+k);}OUTPUT:BM computerk=12,C program k=936, 123, 48IrogramcomputerV.Check Error in the program according to the following description and correct them, write the whole corrected program on the answer sheetA programmer wants to write a program to simulate a roll of the dice. The programmerdecides to have the program choose two pseudo-random numbers from 1 to 6 and output the two numbers. If two values are the same, the program should also output the string "That's a pair!" after printing the two values.The programmer writes the following code:#include <stdio.h>#include <stdlib.h>#include <time.h>int main(void){ int dice[2];srand(time(NULL));for (x = 0; x <= 2; x++);dice[x] = rand() % 6;printf ("You rolled a %d and a %d.\n", dice[0], dice[1]);if (dice[0] = dice[1])printf("That's a pair!\n");return 0;}The above code has 5 errors in it!What are they?没有定义xfor (x = 0; x <= 2; x++);应改为for (x = 0; x <= 2; x++)dice[x] = rand() % 6;应改为(dice[x] = rand() % 7)+1 /*超纲*/for (x = 0; x <= 2; x++);应改为x < 2if (dice[0] = dice[1])应改为==VI.Writing a programWrite a complete program that allows the user to enter a string (assumed to be less than 25 characters long). If N is the length of the string, the program should output N rows to standard output. The first row should be the string entered by the user. The second row should be the string without its last character. The third row should be the string without its last two characters. Etc. The N th and final row should be only the first letter of the string.Here is a sample run, assuming the user types “Hello World!” when prompted:Enter a string: Hello World!Hello World!Hello WorldHello WorlHello WorHello WoHello WHelloHelloHellHelHeHPretest and posttest loop;modular programs;binary operator;file;the amount of storage;continue break statement;Automatic variable;symbolic name;array name;Extern storage class;Identifiers;Escape Sequence;control string;union;compound statement;members of a structure;源代码:#include<stdio.h>#include<string.h>#define N 25main(){char a[N];int i,j;gets(a);for(i=0;i<strlen(a)-1;i++){for(j=0;j<strlen(a)-i-1;j++)printf("%c",a[j]);printf("\n");}}。