[2015 Hunan University 829 postgraduate entrance examination questions]

Test questions of the entrance examination for postgraduates enrolled by Hunan University in 2015

1, Single choice questions (3x10=30)

  1. In C language, the following correct description of the for loop is (D)
    A. The for loop can only be used when the number of cycles has been determined
    B. The for loop executes the loop body statement first, and then judges the expression
    C. In a for loop, you cannot use the break statement to jump out of the loop body X
    D. The loop style sentence of the for loop can contain multiple statements, but must be enclosed in curly braces

  2. The necessary functions in C language program are (B)
    A,#include "stdio.h"
    B,main
    C,printf
    D,scanf

  3. In C language, when referring to an array element, the data type of its array subscript is allowed to be (C)
    A. Integer constant
    B. Integer expression
    C. Integer constant or integer expression
    D. Any type of expression

  4. If x and y are defined as integer variables, x=2; Then the value of the expression y=3.75+x/2 is (C)
    A,6.5
    B,6
    C,4
    D,5.0

  5. For the statement int *px[10], the following statement is correct (B)
    A. px is a pointer to an array whose elements are integers
    B. px is an array in which each element is a pointer to an integer
    C. Both A and B are wrong, but * px is allowed to define arrays in C language
    D. C language does not allow such a definition

  6. An algorithm should have five characteristics such as "certainty". The error in the following description of other characteristics is (B)
    A. There are zero or more inputs
    B. There can only be zero or one output
    C. Poverty
    D. Effectiveness

  7. The correct one in the following statement is (C)
    A. C language programs always start from the first defined function
    B. In C language programs, the function to be called must be defined in the mian() function
    C. C language programs always execute from the main() function
    D. The main() function in C language program must be placed at the beginning of the program

  8. The output of the following program is (B)

#include <stdio.h>
int m=13;
int fun(int x,int y)
{
    int m=3;
    return(x*y-m) ;
}
void main()
{
    int a=7 ,b=5;
    printf%d\n",fun(a,b)/m);
}

A,1
B,2
C,7
D,10

  1. The following array definitions are incorrect (D)
    A,int a[2];
    B,int b[ ] ={ 0,1,2,45,8 };
    C,float a[100][100];
    D,int d[3][3]= {({1,2},{1,2,3},{1,2.3.4}};

  2. The output of the following program segments is (C)

float x=213.82631;
printf("%3d" ,(int)x);

A,213.82
B,213.83
C,213
D,3.8

2, Fill in the blanks (3 * 10 = 30)

  1. The number used in the internal operation of the computer is____ Hexadecimal// two
  2. The basic unit of C language source program is ___, It consists of multiple statements, which are used to realize a specific function and can be used by calling// function
  3. Assuming x=10, the expression x < = 10? The value of 70:34 is_____// seventy
  4. If x = 5 and y = 10, the values of X and y are respectively____ And______// 6 60
  5. The decimal value corresponding to the numeric constant 0x62 is __// 6*16+2=98
  6. In the loop body of C language program, use_______ Statement can jump out of the loop body and execute the statement after the loop body// Break
  7. The running result of the following program is
#include<stdio.h>
main( )
{
    int i,x,y;
    i=x=y=0;
    do
    {
       ++i;
       if( i%2!=0)
          {x=x+i;i++;};
       y=y+i++;
    }while(i<=7);
    printf("x=%d,y=%d\n",x,y);//x=1.y=20
}
  1. Please fill in the two statements in the following program. Each statement is filled in as a blank. Use the rolling division method to find the maximum common divisor of two integers
main( )
{
    int a,b,r;
    scanf("%d%d',&a ,&b);
    __________;//r=a%b
    while(r!=0)
    {
       a=b;
       _____;//b=r
       r=a%5;
    }
    printf(%d",b);
}

3, Judgment questions (2 * 10 = 20)

  1. Recursive calls cannot directly or indirectly call the function itself. ×

  2. The computer cannot directly recognize and execute the source program written in C language. The C source program must be translated into the target program in binary form by compiler before it can be executed normally. √

  3. Each element in the array must belong to the same data type. √

  4. The continue statement in C language only ends this cycle, not the execution of the whole cycle. √

  5. For global variables, a storage area is allocated at the beginning of program execution, and it is released after program execution. √

  6. Algorithm is the method and step taken to solve a problem. ALGORITHM = data structure + program. ×

  7. The strcmp function can be used to connect strings in two character arrays. ×

  8. The execution process of do... while statement is to unconditionally execute the loop body, and then judge whether the loop condition is true. √

  9. C language stipulates that the identifier can only be composed of letters, numbers and underscores, and the first character can be a number. ×

  10. The fclose function can be used to close the data file. Closing is to revoke the file information area and file buffer, so that the file pointer variable no longer points to the file. √

4, Short answer (5 * 10 = 50)

  1. Briefly state the advantages and disadvantages of the pointer

advantage:
(1) It can improve the compilation efficiency and execution speed of the program, and make the program more concise.
(2) Through the pointer, the called function can return other data other than the normal return value to the calling function, so as to realize the two-way communication between the two.
(3) Dynamic memory allocation can be realized by using pointers.
(4) Pointers are also used to represent and implement various complex data structures, so as to lay the foundation for writing higher quality programs.
(5) The memory address can be directly manipulated by using pointers, which can complete similar work with assembly language.
(6) It is easy to write and call functions.
Disadvantages:
Error prone. If the pointer cannot be correctly understood and flexibly and effectively applied, the program written with pointer is more likely to contain all kinds of errors, and the readability of the program will be greatly reduced

  1. What are the characteristics of machine language and high-level language

Machine language: it can be immediately recognized and executed by the machine. It has the advantages of fast execution speed and small memory occupation, but it is difficult to learn, remember and popularize.
High level language: it makes up for the deficiency of machine language. It does not depend on specific machines. It is easy to understand and more convenient.

  1. Find the first 50 values of Fibonacci sequence in array and output them to the screen
#include<stdio.h>
int main()
{
	int i;
	double f[50] = { 1.0,1.0 };//Cannot use int, the 47th start overflow
	for (i = 2; i < 50; i++)
		f[i] = f[i - 1] + f[i - 2];
	for (i = 0; i < 50; i++)
	{
		if (i % 5 == 0)
			printf("\n");
		printf("%15.0lf", f[i]);
	}
	printf("\n");
	return 0;
}
  1. There is an array a containing N integers. Write a C language program and call the function to rearrange and store n integers in reverse order
#include<stdio.h>
int invet(int a[], int n);
int main()
{
	int i;
	int a[10] = { 0,1,2,3,4,5,6,7,8,9 };
	int n = 10;
	invet(a, 10);
	for (i = 0; i < n; i++)
		printf("%d ", a[i]);
	return 0;
}

int invet(int a[], int n)
{
	int i, b[10];
	for (i = 0; i < n; i++)
		b[n - i - 1] = a[i];
	for (i = 0; i < n; i++)
		a[i] = b[i];
}
  1. A ball falls freely from a height of 200 meters, and the bounce height after landing is half of the original height. Write a C language program to ask him the total movement distance when landing for the tenth time and how high is the bounce for the tenth time
#include<stdio.h>
int main()
{
	float sn = 200.0;
	float hn = sn / 2;
	int n;
	for (n = 2; n <= 10; n++)
	{
		sn = sn + 2 * hn;
		hn = hn / 2;
	}
	printf("the total of road is %f\n", sn);
	printf("the tenth is %f meter\n", hn);
	return 0;
}

5, Case analysis (20 points)

Problem Description: input any four digit integer from the keyboard, and then check whether it is an integer multiple of 11;

(1) If it is an integer multiple of 11, the number is output to the screen

(2) If it is not an integer multiple of 11, rearrange the four numbers that make up the number to form a new four digit integer. Among all the four digit integers that can be formed, all the numbers that are an integer multiple of 11 are output to the disk file C:\output.dat (the numbers are separated by commas), and then read the disk file C:\output.dat to find the maximum number and output it to the screen.

(3) If there is no integer multiple of 11 in the second step, output "None" on the screen.

1. Briefly describe the algorithm idea and draw its flow chart (10 points)

2. Write the implementation code of the above requirements in C language (10 points)

#include<stdio.h>
#include<stdlib.h>

int checkFun(int num, int num_11[]);
void save(int num_11[], int count);
void printMax();

int main()
{
	int num_in;
	int num_11[24];
	int count = 0;

	printf("Enter an integer of four digits:");
	scanf("%d", &num_in);
	
	if (num_in > 9999 || num_in < 1000)
	{
		printf("Enter integer error\n");
		return 1;
	}
	if (num_in % 11 == 0)//Is an integral multiple of 11
	{
		printf("%d\n", num_in);
		return 0;
	}
	
	count = checkFun(num_in, num_11);

	if (count > 0)//Reorganization exists as an integer multiple of 11
	{
		save(num_11, count);
		printMax();
	}
	else//non-existent
	{
		printf("nothing");
	}
	return 0;
}

int checkFun(int num, int num_11[])//Check that the reorganization is divided by 11
{
	int div[4];//Save four digits
	int numTemp;
	int count = 0;//Count the number that can be divided by 11
	int i1, i2, i3, i4, j;
	for (j = 3; j >= 0; j--)//Find the number on each digit
	{
		div[j] = num % 10;
		num /= 10;
	}
	for (i1 = 0; i1 < 4; i1++)
		for (i2 = 0; i2 < 4; i2++)
			for (i3 = 0; i3 < 4; i3++)
				for (i4 = 0; i4 < 4; i4++)
				{
					if (i1 != i2 && i1 != i3 && i1 != i4 && i2 != i3 && i2 != i4 && i3 != i4 && div[i1] != 0)
					{
						//Judge four digits, and thousands cannot be 0
						numTemp = div[i1] * 1000 + div[i2] * 100 + div[i3] * 10 + div[i4];
						if (numTemp % 11 == 0)
						{
							for (j = 0; j < count; j++)
							{
								if (numTemp == num_11[j])
									break;
							}
							if (j >= count)//Ignore duplicate numbers
							{
								num_11[count++] = numTemp;
							}
						}
					}
				}
	return count;
}

void save(int num_11[], int count)//Save to file
{
	FILE *fp;
	int i;
	if ((fp = fopen("C:\\output.txt", "w")) == NULL)
	{
		printf("Can not open file!\n");
		exit(0);
	}
	for (i = 0; i < count - 1; i++)
	{
		fprintf(fp, "%d,", num_11[i]);//Separated by commas
	}
	fprintf(fp, "%d", num_11[count-1]);
	fclose(fp);
}

void printMax()//Find the maximum value from the file
{
	int i;
	int numTemp;
	int max = 0;
	FILE* fp;
	if ((fp = fopen("C:\\output.txt", "r")) == NULL)
	{
		printf("Can not open file!\n");
		exit(0);
	}
	while (!feof(fp))
	{
		fscanf(fp, "%d,", &numTemp);
		if (numTemp > max)
			max = numTemp;
	}
	printf("The Max num is:%d\n", max);
	fclose(fp);
}

Tags: C

Posted on Tue, 07 Sep 2021 15:04:32 -0400 by nayone