0
点赞
收藏
分享

微信扫一扫

2021年湖南省对口高考真题

一、选择题

1、

若"int a=-7,b=-1;",执行 "a%=b-1;"后,a的值是__________。         

A.-7               B.-1               C.-2               D.-3

2、

C语言程序从程序中的__________开始执行。

A.第一条语句                           B.第一条可执行语句

C.main函数                            D.第一个函数

3、

若" char a[8]="1234";int x=strlen(a),y=sizeof(a);",

则x和y的值分别是__________。

A.4,4              B.5,4              C.4,5              D.4,8

二、程序填空题

1、

计算圆的面积s(公式为s=3.14π2)。请补全下列代码

#include "stdio.h" 
_____ 1 _____ 3.14
_____ 2 _____
main()
{
    float r=2.5;
    float area=0.0;
    area=_____ 3 _____
    printf("area=%f\n",_____ 4 _____);
    return 0;
}
float
ComputeArea(float r)
{   return (PI*r*r);  }

三、写程序结果

1、

下列程序运行时,若输入:12345,则程序的输出结果是__________。

#include "stdio.h" 
main()
{
    char a,b;
    scanf("%c%*2c%c",&a,&b);
    printf("%c%c\n",a,b);
    return 0;
}

2、

下列程序的运行结果是__________。

#include "stdio.h" 
main()
{
    int a=5,b=6,result=0;
    result=(a>b)?(a>>1):(b<<1);
    printf("result=%d\n",result);
    return 0;
}

3、

下列程序的运行结果是__________。

#include "stdio.h" 
main()
{
    int i=0,j=0;
    do
    {
        printf("%d:",i);
        for(j=i;j<10;j++)
        {
            printf("%d",j);
        }
        printf("\n");
    }while(++i<1);
    return 0;
}

4、

下列程序的运行结果是__________。

#include "stdio.h" 
int a=5;
main()
{
    int a=3;
    {
        int a=1;
        a++;
    }
    printf("a=%d\n",a++);
    return 0;
}

5、

下列程序的运行结果是__________。

#include "stdio.h" 
func(int n)
{
    if(!n) return 0;
    printf("%d",n);
    return func(--n);
}
main()
{
    int a=9;
    func(a);
    return 0;
}

四、程序填空

1、

下列程序的功能是使用二分查找法在给定数组中查询某个数据。

#include <stdio.h>
int binarySearch(____ 1 ____,int bound,int value)
{
    int lowKey=0,highKey=0,midKey=0,midValue=0;
    highKey=____ 2 ____;
    while(lowKey<=highKey)
    {
        midKey=____ 3 ____;
        midValue=lib[midKey];
        if(midValue<value )
            lowKey=midKey+1;
        else if (midValue>value)
            highKey=midKey-1;
        else
            return  midKey;
    }
    ____ 4 ____;
}
int main()
{
    int i=0,value=0,result=0;
    int lib[10]={-20,-5,8,11,26,31,42,55,64,79};
    for (i=0; i<10; i ++)
        printf ("%d\t",lib[i]);
    printf("\n输入要查找的数:");
    scanf ("%d",____ 5 ____);
    result =binarySearch(lib,10,value);
    if (-1==result)
        printf ("查找失败\n");
    else
        printf ("查找成功 index=%d\n",result);
    return 0;
}

五、改错

1、

下列程序的功能是:输入不超过10个数,交换其中最大数和最小数的位置。

该程序只允许修改三行。

#include "stdio.h" 
#define ARR_SIZE 10;
void MaxMinExchang(int a[],int n)
{
    int maxValue=a[0],minValue=a[0],maxPos,
    int i,temp;
    for(i=0;i<n;i++){
        if(a[i]>maxValue){
            maxValue=a[i];
            maxPos=i;
        }
        else{
            minValue=a[i];
            minPos=i;
        }
    }
    temp=a[maxPos];
    a[maxPos]=a[minPos];
    a[minPos]=temp;
}
main()
{
    int data[ARR_SIZE],i,n;
    printf("Input n(n<10):");
    scanf("%d",&n);
    printf("Input %d Numbers:\n",n);
    for(i=0;i<n;i++){
        scanf("%d",data[i]);
    }
    MaxMinExchang(data,n);
    printf("After MaxMinExchange:\n");
    for(i=0;i<n;i++){
        printf("%d ",data[i]);
    }
    printf("\n");
    return 0;
}

2、

下列程序的功能是:寻找斐波拉切数列中的第n个数

斐波拉切数列的定义为:Fib(0)=0; Fib(1)=1; Fib(n)= Fib(n-1)+ Fib(n-2)(n>=2,n∈N);

以下程序只允许修改两行。

#include "stdio.h" 
unsigned long Fib(int n)
{
    if(n<0){
        printf("data error!\n");
        return 0;
    }else if(n==0||n==1){
        return 1;
    }else{
        return Fib(n-1,n-2);
    }
}
main()
{
    int n;
    long fn;
    printf("Input n:");
    scanf("%d",&n);
    fn=Fib(n);
    printf("fib(%d)=%ld\n",n,fn);
    return 0;
}

六、程序设计题

1、

下列程序的功能是:输入两个多项式(每个多项式中的各项都必须按指数从小到大的顺序输入),输入多项式之和。请将程序补充完整,每空可写多条语句。

#include "stdio.h"
#include "stdlib.h"
struct item
{
    int co; //系数
    int ex; //指数 
    struct item *next; 
};
int BuildList(struct item **ppHead);    //输入多项式 
void DisplayList(struct item *phead);   //显示多项式 
int FreeList(struct item **ppHead);     //销毁多项式 
int AddList(struct item *pListAHead,struct item *pListBHead,struct item **ppListCHead);//加法 
int main()
{
    int rv=0;
    struct item *pListAHead=NULL,*pListBHead=NULL,*pListCHead=NULL;
    if(BuildList(&pListAHead) || BuildList(&pListBHead))
    {
        printf("Build List error.\n");
        return 0;
    }
    rv=AddList(____ 1 ____);
    if(rv)
    {
        printf("AddList error.\n");
        return 0;
    }
    DisplayList(pListAHead);
    DisplayList(pListBHead);
    DisplayList(pListCHead);
    FreeList(&pListAHead);
    FreeList(&pListBHead);
    FreeList(&pListCHead);
    return 0;       
} 
int BuildList(struct item **ppHead)
{
    int i=0,n=0;
    struct item *pTail=NULL;
    struct item *pNewItem=NULL;
    printf("Please input total item number");
    scanf("%d",&n);
    if(n<1)
        return 0;
    pTail=(struct item *)malloc(sizeof(struct item));
    if(!pTail)
        return -1;
    printf("please input coefficient and exponent(1):");
    scanf("%d%d",&pTail->co,&pTail->ex);
    *ppHead=pTail;
    for(i=1;i<n;i++)
    {
        pNewItem=(struct item *)malloc(sizeof(struct item));
        if(!pNewItem)
            return -1;
        printf("please input coefficient and exponent(%d):",i+1);
        scanf("%d%d",&pNewItem->co,&pNewItem->ex);
        pNewItem->next=NULL;
        ____ 2 ____;
    }
    return 0;   
} 
void DisplayList(struct item *pHead)
{
    if(!pHead)
        return;
    printf("f(x)=%dx%d",pHead->co,pHead->ex);
    pHead=pHead->next;
    while(pHead)
    {
        printf("+%dx%d",pHead->co,pHead->ex);
        pHead=pHead->next;
    }
    printf("\n");
}
int FreeList(struct item **ppHead)
{
    struct item *pItem=NULL;
    struct item *pNextItem=NULL;
    if(!ppHead || !*ppHead)
        return 0;
    pItem=*ppHead;
    while(pItem)
    {
        ____ 3 ____;
    }
    *ppHead=NULL;
    return 0;
}
int AddList(struct item *pListAHead,struct item *pListBHead,struct item **ppListCHead)
{
    struct item *pListAItem=pListAHead;
    struct item *pListBItem=pListBHead;
    struct item *pItem=NULL;
    struct item *pNewItem=NULL;
    struct item *pTailItem=NULL;
    if(!pListAItem && !pListBItem)
        return 0;
    if(*ppListCHead)
        *ppListCHead=NULL;
    while(pListAItem && pListBItem)
    {
        pNewItem=(struct item *)malloc(sizeof(struct item));
        if(!pNewItem)
            return -1;
        pNewItem->next=NULL;
        if(pListAItem->ex<pListBItem->ex)
        {
            pNewItem->ex=pListAItem->ex;
            pNewItem->co=pListAItem->co;
            pListAItem=pListAItem->next;
        }
        else
			if(pListAItem->ex>pListBItem->ex)
        	{
            	pNewItem->ex=pListBItem->ex;
            	pNewItem->co=pListBItem->co;
            	pListBItem=pListBItem->next;
        	}
        	else
        	{
            	____ 4 ____;
        	}
        if(!*ppListCHead)
            *ppListCHead=pTailItem=pNewItem;
        else
            pTailItem=pTailItem->next=pNewItem;
    }
    if(pListAItem)
        pItem=pListAItem;
    else if(pListBItem)
        pItem=pListBItem;
    while(pItem)
    {
        pNewItem=(struct item *)malloc(sizeof(struct item));
        if(!pNewItem)
            return 0;
        pNewItem->ex=pItem->ex;
        pNewItem->co=pItem->co;
        pNewItem->next=NULL;
        ____ 5 ____;
        if(!*ppListCHead)
            *ppListCHead=pTailItem=pNewItem;
        else
            pTailItem=pTailItem->next=pNewItem;
    }
    return 0;   
}

参考答案:

一、选择题

1—3    B、C、D

二、程序填空题

1、#define PI                  2、float ComputeArea(float r);

3、ComputeArea(r);             4、area

三、写程序结果

1、14               2、result=12            3、0:0123456789         4、a=3         

5、987654321

四、程序填空

1、int lib[10]                                

2、bound-1 或者lowKey+bound-1

3、(lowKey+highKey)/2      4、return -1;       5、&value

五、改错

1、

L02     #define ARR_SIZE 10//#define ARR_SIZE 10;

L12     else if(a[i]<minValue) { //else{

L28     scanf("%d",&data[i]);//scanf("%d",data[i]);

L05     int maxValue=a[0],minValue=a[0],maxPos,minPos;

也应该有错,maxPos,minPos均没有赋初值,若第一个就为最小值,则minPos无初值。

2、

L08     return n;//return 1;

L10     return Fib(n-1)+Fib(n-2);//return Fib(n-1,n-2);

其实第二行可能也有转换问题

L02     long Fib(int n)//unsigned long Fib(int n)

六、程序设计题

1、 pListAHead,pListBHead,&pListCHead 

2、 pTail->next=pNewItem;

    pTail=pTail->next; 

3、 pNextItem=pItem->next;

    free(pItem);

    pItem=pNextItem; 

4、 pNewItem->ex=pListAItem->ex;

    pNewItem->co=pListAItem->co+pListBItem->co;

    pListAItem=pListAItem->next;

    pListBItem=pListBItem->next;   

5、 pItem=pItem->next;

 

 

举报

相关推荐

0 条评论