C Language Computer Level 2/C Language Final Exam Questions (13) Array Topic 2

Collection of some classic C language computer level two and C language final exam question bank

It's not easy to organize, please like and collect to support

I wish you all high scores in the second-level computer and final exams

Series of articles:

C Language Computer Level 2/C Language Final Exam Questions (1)

C Language Computer Level 2/C Language Final Exam Questions (2)

C Language Computer Level 2/C Language Final Exam Questions (3)

C Language Computer Level 2/C Language Final Exam Questions (4)

C Language Computer Level 2/C Language Final Exam Questions (5)

C Language Computer Level 2/C Language Final Exam Questions (6)

C Language Computer Level 2/C Language Final Exam Questions (7)

C Language Computer Level 2/C Language Final Exam Questions (8)

C Language Computer Level 2/C Language Final Exam Questions (9)

C Language Computer Level 2/C Language Final Exam Questions (10) Function Topics

C Language Computer Level 2/C Language Final Exam Questions (11) Topics on Data Types and Input and Output

C Language Computer Level 2/C Language Final Exam Questions (12) Array Topic 1

Table of contents

1. Fill in the blanks, a total of 10 questions (10 points in total)

2. Single choice, a total of 15 questions (total 15 points)

3. Program to fill in the blanks, 2 questions in total (30 points in total)

4. Program error correction 1 question in total (total 15 points)

V. Program Design 1 question in total (30 points in total)


1. Fill in the blanks, a total of 10 questions (10 points in total)

Question 1

If there is the following array a, array elements: a[0]~a[9], its value is

  9  4  12  8  2  10  7  5  1  3

 The minimum subscript value available for this array is【1】.

=======(Answer 1)=======

0

Question 2

If there is the following array a, array elements: a[0]~a[9], its value is

 9  4  12  8  2  10  7  5  1  3

 Among the elements of the array, the subscript value of the element with the largest value is [1].

=======(Answer 1)=======

2

Question 3

In memory order, all elements in the array char a[2] are a[1] and [1].

=======(Answer 1)=======

a[0]

Question 4

The library function for finding the length of a string is [1], just write the function name.

=======(Answer 1)=======

strlen

Question 5

If there is the following array a, array elements: a[0]~a[9], its value is

 9  4  12  8  2  10  7  5  1  3

 Among the elements of the array, the subscript value of the element with the smallest value is [1].

=======(Answer 1)=======

8

Question 6

The array occupies a continuous storage area in the memory, and [1] represents its first address.

=======(Answer 1)=======

array name

Question 7

The library function for copying strings is [1], just write the function name.

=======(Answer 1)=======

strcpy

Question 8

In C language, the minimum subscript of an array element is [1].

=======(Answer 1)=======

0

Question 9

Define int a[2][3]; means that the number of elements in array a is [1].

=======(Answer 1)=======

6

Question 10

Enter 1 2 3 4 5 6 7 8 9 from the keyboard, and the output result after execution is 【1】.

main()

{   int a[3][3],i,sum=0;

    for(i=0;i<3;i++)

        for(j=0;j<3;j++)

           scanf("%d",&a[i][j]);

   printf("\n");

   for( i=0; i<3; i++ )  sum = sum + a[i][i];

   printf("%d\n",sum);

 }

=======(Answer 1)=======

15

2. Single choice, a total of 15 questions (total 15 points)

Question 1

To determine whether the string s1 is greater than the string s2, use ().

A:if(s1>s2)

B:if(strcmp(s1,s2))

C:if(strcmp(s2,s1)>0)

D:if(strcmp(s1,s2)>0)

Answer: D

Question 2

If there is an array definition: char array[ ]="China";, then the space occupied by the array array is ().

A:4个字节

B:5个字节

C:6个字节

D:7个字节

Answer: C

Question 3

If there is a description of int a[3][4]; then the illegal reference of a array element is ().

A:a[0][2*1]

B:a[1][3]

C:a[4-2][0]

D:a[0][4]

Answer: D

Question 4

When calling a function, the actual parameter is an array name, and the function is passed to ().

A:数组的长度

B:数组的首地址

C:数组每一个元素的地址

D:数组每个元素中的值

Answer: B

Question 5

If there is an explanation: int a[ ][4]={0,0};, then the following incorrect statement is ().

A:数组a的每个元素都可得到初值0

B:二维数组a的第一维大小为1       

C:因为二维数组a中初值的个数不能被第二维大小的值整除,
则第一维的大小等于所得商数再加1,故数组a的行数为1

D:只有元素a[0][0]和a[0][1]可得到初值0,其余元素均得不到初值0

Answer: D

Question 6

The correct description of the following one-dimensional integer array a is ().

A:int a(10);

B:int n=10,a[n];

C:int n; scanf("%d",&n); int a[n];

D:#define SIZE 10  (换行)  int a[SIZE];

Answer: D

Question 7

There are the following programs:

        #include<stdio.h>

        #include<string.h>

        void main()

        {  char a[ ]={'a','b','c','d','e','f','g','h','\0'};

           int i,j;

           i=sizeof(a);j=strlen(a);

           printf("%d,%d\n",i,j);  }

The output of the program after running is ().

A:9,9

B:8,9

C:1,8

D:9,8

Answer: D

Question 8

If there is the following definition: int t[3][2]; the expression that can correctly represent the element address of the t array is ().

A:&t[3][2]

B:t[3]

C:&t[1]

D:t[2]

Answer: D

Question 9

If there is a description: int a[3][4]; then the illegal reference to an array element is ().

A:a[0][2*1]

B:a[1][3]

C:a[4-2][0]

D:a[0][4]

Answer: D

Question 10

There is the following program segment:

        char a[3],b[ ]="china";
        a=b;
        printf("%s",a);

but().

A:运行后将输出china

B:运行后将输出ch

C:运行后将输出chi

D:编译出错

Answer: D

Question 11

The following statement that can correctly initialize the two-dimensional array a is ().

A:int a[2][]={
    
    {1,0,1},{5,2,3}};

B:int a[][3]={
    
    {1,2,3},{4,5,6}};

C:int a[2][4]={
    
    {1,2,3},{4,5},{6}};

D:int a[][3]={
    
    {1,0,1}{},{1,1}};

Answer: B

Question 12

If there is an instruction int a[3][4]; then the correct reference to the a array element is ().

A:a[2][4]

B:a[1,3]

C:a[1+1][0]

D:a(2)(1)

Answer: C

Question 13

int i, j, a[2][3]; According to the arrangement order of the elements of the array a in the memory, the number 1, 2, 3, 4, 5, 6 cannot be stored in the array a ().

A:for(i=0;i<2;i++)for(j=0;j<3;j++)a[i][j]=i*3+j+1;

B:for(i=0;i<3;i++)for(j=0;j<2;j++)a[j][i]=j*3+i+1;

C:for(i=0;i<6;i++)a[i/3][i%3]=i+1;

D:for(i=1;i<=6;i++)a[i][i]=i;

Answer: D

Question 14

Assuming that the int type variable occupies two bytes, it has a definition: int x[10]={0,2,4};, then the number of bytes occupied by the array x in memory is ().

A:3

B:6

C:10

D:20

Answer: D

Question 15

The correct description of the following two-dimensional array a is ().

A:int a[3][]

B:float a(3,4)

C:double a[1][4]

D:float a(3)(4)

Answer: C

3. Program to fill in the blanks, 2 questions in total (30 points in total)

Question 1

题目:给定程序中,函数fun的功能是:在任意给定的9个正整数中找出按升序排列时处
     于中间的数,将原数据序列中比该中间数小的数用该中间数替换,位置不变,在
     主函数中输出处理后的数据序列,并将中间数作为函数值返回。

例如:有9个正整数:1  5  7  23  87  5  8  21  45   按升序排列时的中间数为:8
     处理后主函数中输出的数列为:8  8  8  23  87  8  8  21  45
#include <stdio.h>
#define N 9
int fun(int x[])
{
	int i, j, k, t, mid, b[N];
	for (i = 0; i < N; i++)
		b[i] = x[i];
	for (i = 0; i <= N / 2; i++)
	{
		k = i;
		for (j = i + 1; j < N; j++)
			if (b[k] > b[j])
				k = j;
		if (k != i)
		{
			t = b[i];
			b[i] = 【 ? 】;
			b[k] = t;
		}
	}
	mid = b[【 ? 】];
	for (i = 0; i < N; i++)
		if (x[i] 【 ? 】 mid)
			x[i] = mid;
	return mid;
}

main()
{
	int i, x[N] = { 1,5,7,23,87,5,8,21,45 };
	for (i = 0; i < N; i++)
		printf("%d ", x[i]);
	printf("\nThe mid data is: %d\n", fun(x));
	for (i = 0; i < N; i++)
		printf("%d ", x[i]);
	printf("\n");
}

Answer:

=======(答案1)=======
b[k]

=======(答案2)=======
4
=========或=========
N/2

=======(答案3)=======
<

Question 2

题目:求数组a[5]中相邻元素的最大公约数,并保存到数组b[5]中
     (a[4]与a[0]看作相邻元素)。

例如:a[5]={18,66,38,87,15}
     b[5]={6,2,1,3,3}
#include <stdio.h>
#define M 5
void Calculate(int a[], int n, int b[])
{
	int i, x, y, r;
	for (i = 0; i < n; i++)
	{
		x = a[i];
		y = a[【 ? 】];
		do
		{
			【 ? 】;
			x = y;
			y = r;
		} while (r);
		b[i] = x;
	}
}

void main()
{
	int i, n = 5, a[5] = { 18,66,38,87,15 }, b[5] = { 0 };
	Calculate(a, n, b);
	for (i = 0; i < n; i++)
		printf("%3d、%3d的最大公约数:%3d\n", a[i], a[(i + 1) % n], b[i]);
}

Answer:

=======(答案1)=======
(i+1)%n
=========或=========
(1+i)%n

=======(答案2)=======
r=x%y

4. Program error correction 1 question in total (total 15 points)

Question 1

功能:先从键盘上输入一个3行3列矩阵的各个元素的值,然后输
     出主对角线上的元素之和sum。
#include <stdio.h>
void fun()
{
	int a[3][3], sum;
	int i, j;
	a = 0;
	for (i = 0; i < 3; i++)
		for (j = 0; j < 3; j++)
			scanf("%d", a[i][j]);
	for (i = 0; i < 3; i++)
		sum = sum + a[i][j];
	printf("sum=%f\n", sum);
}

main()
{
	fun();
}

Answer:

=======(答案1)=======
sum=0;

=======(答案2)=======
scanf("%d",&a[i][j]);

=======(答案3)=======
sum=sum+a[i][i];
=========或=========
sum+=a[i][i];

=======(答案4)=======
printf("sum=%d\n",sum);

V. Program Design 1 question in total (30 points in total)

Question 1

题目:(一维数组)有n个已经按由小到大排好序的整数,再输入一个整数,
      将其插入到这批数据中,要求插入该元素后仍然按由小到大的顺序排列。
#include <stdio.h>
#define N 11
void main()
{
	int a[N], x, p;
	int i;
	printf("Please input %d numbers:", N - 1);
	for (i = 0; i <= N - 2; i++)
		scanf("%d", &a[i]);
	printf("Please input x to be intert:");
	scanf("%d", &x);
	/**********Program**********/



	/**********  End  **********/
	for (i = 0; i <= N - 1; i++)//结果
		printf("%5d", a[i]);
	printf("\n");
}

Answer:

for (i = 0; i < N - 1; i++)//寻找插入点,并将插入点保存到p中
{
	if (a[i] > x)
	{
		p = i;
		break;
	}
}
printf("i=%d\n", p);
for (i = N - 2; i >= p; i--)//插入点之后元素后移一位,为新元素空出位置
	a[i + 1] = a[i];
a[p] = x; //插入新元素

If you have any mistakes or questions, please leave a message in the comment area for discussion.

Guess you like

Origin blog.csdn.net/qq_57342311/article/details/129891419