[2013 Hunan University 829 postgraduate entrance examination questions]

2013 Hunan University postgraduate entrance examination questions

1, Single choice questions (20 * 1 = 20 points)

Some data is lost, please forgive me!

  1. In the following statement, the definition of p as a pointer array is (A)
    A,int* p[4]
    B,int ( * p)[4]
    C,int*p(4)
    D,int(*p)(4)

2, Briefly answer the following questions (1 * 20 = 20 points)

There are several statements in C language that can realize branches. Please write out the general forms of these statements and draw the corresponding flow chart.

There are mainly if and switch, which have the following forms:

(1) if(expression) {}  
(2) if ......else ...... 
(3) if ......if else ......else ...... 
(4)if(Expression 1)
   {
       if(Expression 2)
       {
           Statement 1;
       }
   }
   else
   {
       Statement 2;
   }  
(5) switch(expression):
     case Value 1:Statement 1; break;
     case Value 2:Statement 2; break;
     ......
     default:sentence n;break; 

flow chart

3, Read the following program and write the running results (10 * 3 = 30 points)

#include<stdio.h>
int main( )
{
    int p = 300;
    printf(%d\n" ,(p/3>0?p/100:p%3));//3
}
#include<stdio. h>
int main( )
{
    char m;
    m ='B'+32;
    printf("%c\n" ,m);//b
}
#include<stdio.h>
int main( )
{
    int a=1,b=3,c=5;
    if(c=a+b) 
       printf("yes\n");//yes
    else
       printf("no\n");
}

Note: This is an assignment, not a size comparison

#include<stdio.h>
int main( )
{
    int i,m=0,n=0,k=0;
    for(i=9;i<=11;i++)
    switch(i/10)
    {
       case 0:m++;n++;break;
       case 10:n++ ;break;
       default:k++;n++;
    }
    printf("%d %d %d\n" ,m,n,k);// 1 3 2
}
#include<stdio.h>
int main( )
{
    int i,j;
    for(i=1;i<5;i++)
        for(j=2;j<=i;j++)
             printf("#");// ######
}
#include<stdio.h>
int main( )
{
    int i,n[]={0,0,0,0,0};
    for(i=1;i<=4;i++)
    {
       n[i] = n[i-1]*2+1;
       printf("%d ",n[i]);// 1 3 7 15
    }
}
#include<stdio.h>
int main( )
{
    int i,j,a[][3]={1,2,3,4,5,6,7,8,9};
    for(i=0;i<3;i++)
       for(j=i+1;j<3;j++)
          a[i][j]=Q;
    for(i-0;i<3;i++)
    {
       for(j=0;j<3;j++)
       printf("%d" ,a[i][j]);// 1 0 0
    printf("\n");            // 4 5 0
    }                        // 7 8 9
}
#include<stdio. h>
int a=5;
fun(int b)
{
    static int a = 10;
    a+=b++ ;
    printf("%d",a);//30
}

int main()
{
    int c=20;
    fun(c);
    a+=c++;
    printf("%d\n",a);//25
}
#include<stdio.h>
int main()
{
    int a=4,b=3,c=5,t=0; 
    if(a<b) t=a;a=b;b=t;
    if(a<c) t=a;a=c;c=t;
    printf("%d %d %d\n" ,a,b,c);// 5 0 3
}

Note: do you think it's very simple? Do you think it's exchange? 5, 3, 4, NO, it's not enclosed in braces,

#include<stdio.h> int main() {
    int a = 4, b = 3, c = 5, t = 0;
    if (a < b)
    {
        t = a; a = b; b = t;
    }
    if (a < c)
    {
        t = a; a = c; c = t;
    }
    printf("%d %d %d\n", a, b, c);// 5 3 4 }

It's very easy to make mistakes here. The statement after if is only one sentence, and stops at the first semicolon; No braces are two logics.

#include<stdio.h>
int main( )
{
    int a[4][4]={{1,2,-3,-4},{0,-12,-13,14},{-21,23,0,-24},
                 {-31,32,-33,0}};
    int i,j,s=0;
    for(i=0;i<4;i++)
    {
       for(j=0;j<4;j++)
       {
          if(a[i][j]<0)continue;
          if(a[i][j] == 0) break;
          S+=a[i]lj];
       }
    }
    printf("%d" ,s);//58
}

4, Procedural blank filling questions (2 points for each blank, 30 points in total)

  1. The program reads 10 integers, counts the number of negative numbers, and calculates the sum of negative numbers.
#include<stdio.h>
int main()
{
    int i,a[10],s,count;
    s = count = 0;
    for(i=0;i<10;i++)
       scanf("%d",_____);// &a[i]
    for(i-0;i<10;i++)
    {
       if(a[i]>=0)
          ________;// continue;
       s+=a[i] ;
       count++ ;
    }
    printf("s=%d, count=%d\n",s, count);
}
  1. The program can input up to 50 characters from the keyboard and send the characters into the array c. when a space is encountered, it is converted into a character '#', and when a newline character ('\ n') is encountered, it ends.
#include<stdio.h>
int main( )
{
    int i;
    char ch,c[100];
    for(i=0;_______;i++)// i<50
    {
       if((ch=getchar()) == '\n')
          __________; // break
       if(ch==' ')
          __________;// ch = '#'
       c[i] = ch;
    }
    c[i] = '\0';
    puts(c);
}
  1. The following program finds the maximum value and small value from ten numbers.
#include<stdio.h>
int max,min;
find_ max_ min(int*p,int n)
{
    int *p;
    for(q=____;____;q++)// p q<p+n
       if(_____)// max<*q
          max = *q;
       else if(_____)// min>*q
          min = *q;
}

int main()
{
    int i,num[10];
    printf("input 10 number:\n");
    for(i=0;i<10;i++)
       scanf("%d" , &num[i]);
    find_ max_ min(num,10);
    printf( "max=%d, min=%d\n",max ,min);
}
  1. The following function fun(int n) calculates the cumulative sum of 1 to n
sum(int n)
{
    if(n<=0)
       printf("data error\n");
    if(n==1)
       _______;// return 1
    else
       _______;// n+sum(n-1)
}
  1. The following program displays the specified file, and then displays the file content with the line number, #include < stdio. H >
#include<string.h>
int main()
{
    char s[20],filenane20J;
    int flag = 1,______;// i=0
    FILE *fp;
    printf("enter filename:!n");
    gets(filename );
    if((fp=fopen(filename,"r"))_______)// ==NULL
       printf("FILE open error!");
    else
    {
       while(_______)// !feof(fp)
       {
          fgets(s,20,fp);
          if(_______)// flag==1
             printf("%3d ,%s",++i,s);
          else
             printf("%s",s);
          if(s[strlen(s)-i]=='\n')
             flag = 1;
          else
             flag = 0; 
       }
    }
    fclose(fp);
}

5, Programming questions (50 points)

  1. The program will output the rectangular pattern shown in Figure 1, and the flow chart of the program is shown in Figure 2: Please complete the following work:

(1) Write a program to complete the design
(2) The output module is designed as an independent function: the writing process is often to complete the pattern output by calling the function;
(3) draw the flow chart of the output module function( (20 points)
[for reference only]

#include<stdio.h>
void output(int, int);
int main()
{
	int i, m, n;
	scanf("%d%d",&m, &n);
	if (m > n && m > 0 && n > 0)
		output(m, n);
	else
		printf("Error in input data");
	return 0;
}

void output(int m, int n)
{
	int i, j;
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < n; j++)
			printf("*");
		printf("\n");
	}
}
  1. Design a bubble sorting function: void mysort(int num[],int n). Use the stomach bubble method to sort the integer numbers of n people in ascending order, and write a program for debugging( (30 points)
    [for reference only]
void mysort(int num[], int n)
{
	int i, j, t, a = { 0 };
	for (i = 0; i < n - 1; i++)
	{
		for (j = 0; j < n - i - 1; j++)
		{
			t = a[j];
			a[j] = a[j + 1];
			a[j + 1] = t;
		}
	}
}

Keywords: C

Added by roustabout on Mon, 06 Sep 2021 06:21:41 +0300