Qingdao University Fall 2018 "C Language Programming" Final Simulation Exercise-Part I (70 minutes)

Qingdao University Fall 2018 "C Language Programming" Final Simulation Exercise-Part I (70 minutes)
Start time 1/1/2016, 12:00:00 AM
End time 1/18/2038, 12:00:00 AM
70 minutes to answer the question
Candidate Xiaowang
Total score 60

Total score for true or false questions: 20
1-1

The loop in the following program will be an infinite loop, and the program will always run and cannot be terminated (assuming that the computer system running the program will never crash or lose power due to unexpected circumstances). (2 minutes)

       

#include "stdio.h"
int main(){
    for(long num=1; num>0; num++)
        printf("%ld\n", num);
    return 0;
}
1-2

Suppose a certain program language C defines two variables a, band the two variables is not 0, the expression a / bvalue of 0 will not. (2 minutes)

       

1-3

Assuming the definition is as follows: int array[5][10];the statement defines an array array. Wherein the array is a pointer to a pointer type (two pointers), namely: int **. (2 minutes)

       

1-4

The following code, the result of the printout is 133. (2 minutes)

       

#include <stdio.h>
int main(){
    int a,b;
    a = 012;
    b = 123;
    printf("%d", a+b);
    return 0;
}
1-5

The following code is not standardized, and the program may run incorrectly. The reason is that the plocal variables are accessed through pointers tmp, and tmpthe space hohohas been released after the function runs. (2 minutes)

       

int* hoho(int n){
    int tmp;
    tmp += n;
    return &tmp;
}
/* 此处省略若干行代码 */
int main(){
    /* 此处省略若干行代码 */
    int *p;
    p = hoho(3);
    /* 此处省略若干行代码,且这些代码不会修改p的值 */
    *p = 6;
    return 0;
}

1-6

Regarding C language pointer operations: pointers only have addition and subtraction operations, not multiplication and division operations. Pointers can add and subtract constants; pointers of the same type can be subtracted, but cannot be added. (2 minutes)

       

1-7

sizeof(int)The number of bytes of memory occupied by an integer can be calculated, but it is sizeof( )not a function, but an operator (operator). (2 minutes)

       

1-8

Global variables defined in C language are stored in the stack area, and local variables are stored in the heap area. (2 minutes)

       

1-9

C language, %is the modulo (remainder) operator eyes, its two operands (operand) must be an integer (e.g. int, short, charetc.), can not float (e.g. double, float). (2 minutes)

       

1-10

The following piece of code uses the %.2fformat to print out the intvariable without type conversion, and the result of the printout will not be 2019.00. (2 minutes)

       

#include <stdio.h>
int main(){
    int k=2019;
    printf("%.2f", k);
    return 0;
}
Total score for multiple choice questions: 20
2-1

The following code, the syntax is correct: (2 points)

2-2

The following names cannot be used as C language identifiers: (2 points)

2-3

Execute the following procedure, the content of the printout is: (2 points)

#include <stdio.h>
int x=5;
void incx( ){
    x++;
}
int main( ){
    int x=3;
    incx( );
    printf("%d\n", x);
    return 0;
}
2-4

Definition of variables int a;, the expression a = 3, 5;after the execution, avalues and expressions are: (2 minutes)

2-5

Consider the following variables are defined int a, k;then the following statement which does not ensure the variable kvalue becomes zero: (2 points)

2-6

Definition of int score = 75;the expression 80 < score < 90values is: (2 minutes)

2-7

The asum bof variables is a doubletype, aand bthe most appropriate way of judging that it is equal to the value is: (2 points)

2-8

Defined char a;then the following assignment statement is inappropriate: (2 points)

2-9

Execute the following program segment, the content of the printout is: (2 points)

#include <stdio.h>
void fun (int c, int *d) {
    c++;
    (*d)++;
}
int main ( ){
    int a=1, b=2;
    fun(a, &b);
    printf("%d, %d", a, b);
    return 0;
}
2-10

For the definition char str[] = "abc\0def";(note: 0the number is zero), find the length len of the string str (that is, calling the standard library function strlen:) len = strlen(str)and the size of the array str (that is size = sizeof(str)), len and size are: (2 points)

Total marks for filling in the blanks: 10
4-1

Execute the following procedure,

#include <stdio.h>
int main( ){
    int array[10]={2, 12, 24, 36, 48, 49, 2333, 6666, 23333, 99999};
    int key=2333, flag=0, low=0, m, h=9, times=0;
    while(low <= h){
        m = (low + h) / 2;
        times++;
        if(array[m] == key) {
            printf("Found-%d-%d", m, times);
            flag = 1;
            break;
        }
        else if(array[m] > key) h = m - 1;
        else low = m + 1;
    }
    if(flag == 0) printf("Not Found!");
    return 0;
}

The result of running the program (that is, what is printed on the screen) is _____________ (5 points) .
(Note: To fill in the answer strict accordance with the format of the printed program, including uppercase and lowercase letters, how many spaces, hyphens -and exclamation !formats, etc., are not free to increase quotes, spaces and other extraneous characters, otherwise no points for example. printf(“hello World”);Content is printing hello World, Not "hello World". In order to prevent formatting errors, it is recommended to directly copy part of the relevant content from the above code.)

4-2

Perform the following procedures:

#include <stdio.h>
int main( ){
    int score, bonus;
    score = 60;
    bonus = 3;
    switch(bonus){
    case 1:
        score += 10;
    case 2:
        score += 20;
    case 3:
        score += 30;
    default:
        score -= 9;
    }
    printf("%d", score);
    return 0;
}

The result of running the program (that is, what is printed on the screen) is _____________ (3 points) . (Note: You must fill in the answers strictly in accordance with the format printed by the program. Do not add extraneous characters such as quotation marks and spaces at will, otherwise you will not receive a score. For example, the printf("hello World");printed content is hello World, not "hello World".)

4-3

Perform the following procedures:

#include <stdio.h>
int main( ){
    int num, r;
    num = 16;
    r = num % 2;
    if(r=0) printf("even");
    else printf("odd");
    return 0;
}

The result of the program operation (ie: the content printed on the screen) is (_____________ 2 points) . (Note: Fill in the answers strictly in accordance with the format printed by the program, pay attention to the capitalization of letters, and do not add quotation marks, spaces and other extraneous characters at will, otherwise they will not be scored. For example, the printf("hello World");printed content is hello World, not "hello World")

5-1

The following program prints the highest digit of the integer num entered (for example 321, if you enter it , it will be printed 3; if -678it is entered , it will be printed 6). Please fill in the vacant code.

#include <stdio.h>
int main(){
    int num;
    scanf("%d", &num);
    int digit=0;
    if( num < 0)  _____________(1分) ;
    while( _____________(1分) ){
        _____________(1分);
        num = _____________(1分) ;
    }
    printf("%d\n", digit);
    return 0;
}
5-2

The mathematician Hilbert put forward a "twin prime conjecture" in the report of the International Congress of Mathematicians in 1900, that is,
there are infinitely many prime numbers p, so that p + 2 is a prime number. The pair of prime numbers with a difference of 2 between p and p+2 is called a "twin prime number".
It seems that this conjecture is valid. We can always find many pairs of twin primes, such as 3 and 5, 5 and 7, 11 and 13... This conjecture has not been proven yet.
The following program for input integer n(n <100000), find greater than n the smallest pair of twin primes pand q(q = p + 2, and it is believed that you, which can be found within a certain range of integer variables Right pand q).

int isPrime(int num){
    for(int i=2; i<=num/2; i++)
        if( _____________(2分) ) return 0;
    	return 1;
}
int main(){
    int n;
    for(int i=0; i<6; i++) {  // 总共寻找6次
        scanf("%d",&n);   //输入一个整数n
        if( _____________(2分)) printf("3 5\n");
        else{
            for(n++;  _____________(2分); n++);   //注意看清楚,此行代码中所要填的空之后带有分号
            printf("%d %d\n",n, n+2);
        }
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_42403632/article/details/104122252