第1周——指针1

函数指针的定义和初始化

1、判断题:
int (*f)(int, int);‏这条语句定义的是一个函数指针f,它可以指向一个有两个整型形参和整型返回值的函数。假设‏int Fun(int a, int b);‏‍那么必须用f=Fun();对f进行初始化,让其指向函数Fun()。‏
选项:
A: 正确
B: 错误
答案: 【 错误

指针变量做函数参数与普通变量做函数参数的区别

1、判断题:
‎普通变量做函数参数,是将实参值的一个副本传给形参,而指针变量做函数参数是将变量的地址值传给形参,因此你想要修改哪个变量的值,将这个变量的地址传给指针形参就好了。‍‎‍
选项:
A: 正确
B: 错误
答案: 【 正确

指针的概念

1、单选题:
‍下列说法错误的是()。‌
选项:
A: 指针变量占用的内存单元字节数就是它所指向的变量所占用的内存单元字节数。
B: 指针变量指向的数据的类型,称为指针的基类型。指针变量只能指向同一基类型的变量。
C: 指针变量使用之前必须初始化,如果你不知道该用什么值对其进行初始化的话,那么就先用NULL对其进行初始化。使用未初始化的结果将是无法预知的。
D: 通过间接寻址运算符引用指针变量指向的变量的值,称为指针的解引用。
答案: 【 指针变量占用的内存单元字节数就是它所指向的变量所占用的内存单元字节数。

第1次测验

1、单选题:
‍下面程序的功能是输入某年某月某日,计算并输出它是这一年的第几天。‍‍程序的运行结果如下:‍‍Please enter year, month, day:2014,12,29↙‍‍yearDay = 363‍‍按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。‍‍‍‍#include    <stdio.h>
int  DayofYear(int year, int month, int day);
int dayTab[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int main()
{
    int year, month, day, yearDay;
    printf("Please enter year, month, day:");
    scanf("%d,%d,%d", &year, &month, &day);
    yearDay = DayofYear(year, month, day);
    printf("yearDay = %dn", yearDay);
    return 0;
}

/* 函数功能:对给定的某年某月某日,计算并返回它是这一年的第几天 */
int  DayofYear(int year, int month, int day)
{
    int  i, leap;
    leap = ________________________;  /* 若year为闰年,即leap值为1,则用第1行元素dayTab[1][i]计算;
                                       否则leap值为0,用第0行dayTab[0][i]计算 */
    for (i=1; _______; i++)
    {
        day = ________________;
    }
    return day;         /* 返回计算出的day的值 */
}‍
选项:
A: 第18行:  ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)第20:    i<month第22行:  day + dayTab[leap][i]
B: 第18行:  ((year % 4 == 0) || (year % 100 != 0)) || (year % 400 == 0)第20:    i<month第22行:  day + dayTab[i][leap]
C: 第18行:  ((year % 4 == 0) && (year % 100 != 0)) && (year % 400 == 0)第20:    i<12第22行:  day + dayTab[leap][i]
D: 第18行:  ((year % 4 != 0) && (year % 100 != 0)) || (year % 400 != 0)第20:    i<=month第22行:  day + dayTab[i][leap]
答案: 【 第18行:  ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)第20:    i<month第22行:  day + dayTab[leap][i]

2、单选题:
‌下面程序的功能是从键盘输入10个整数,用函数编程实现计算其最大值和最小值,并互换它们所在数组中的位置。程序运行结果如下:‏‌Input n(n<=10):10↙‏‌Input 10 Numbers:1 4 3 0 –2 6 7 2 9 -1 ↙‏‌Exchange results:     1     4     3     0     9     6     7     2    -2    -1‏‌按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。‏‌‏‌#include  <stdio.h>
void ReadData(int a[], int n);
void PrintData(int a[], int n);
void  MaxMinExchang(int a[], int n);
void Swap(int *x, int *y);
int main()
{
    int  a[10], n;
    printf("Input n(n<=10):");
    scanf("%d", &n);
    printf("Input %d numbers:", n);
    ReadData(a, n); 
    MaxMinExchang(a, n);
    printf("Exchange results:");
    PrintData(a, n); 
    return 0;
}

/* 函数功能:输入数组a的n个元素值 */
void ReadData(int a[], int n)  
{
    int i;
    for (i=0; i<n; i++)
     {
          scanf("%d", &a[i]);
     }
}

/* 函数功能:输出数组a的n个元素值 */
void PrintData(int a[], int n)  
{
    int i;
    for (i=0; i<n; i++)
     {
          printf("%5d", a[i]);
     }
    printf("n");
}

/* 函数功能:将数组a中的最大数与最小数位置互换 */
void  MaxMinExchang(________, int n)
{
    int  maxValue = a[0], minValue = a[0], maxPos = 0, minPos = 0;
    int  i;
    for (i=1; i<n; i++)
    {
        if (a[i] > maxValue)
        {
            maxValue = _______;
            maxPos = ____;
        }
        if (a[i] < minValue)
        {
            minValue = a[i];
            minPos = i;
       }
}
        Swap(________________);
}

/* 函数功能:两整数值互换 */
void  Swap(int *x, int *y)                
{
    int  ________;
    temp = *x;                          
    _________; 
                   
    *y = temp;            
}‏
选项:
A: 第41行: int a[]第49行: a[i]第50行: i第58行: &a[maxPos], &a[minPos]第64行: temp第66行: *x = *y
B: 第41行: int a第49行: a[i]第50行: i第58行: a[maxPos], a[minPos]第64行: temp第66行: *x = *y
C: 第41行: int a[]第49行: a[0]第50行: 0第58行: &a[maxPos], &a[minPos]第64行: *temp第66行: x = y
D: 第41行: int a[]第49行: a[n-1]第50行: n-1第58行: *a[maxPos], *a[minPos]第64行: &temp第66行: x = y
答案: 【 第41行: int a[]第49行: a[i]第50行: i第58行: &a[maxPos], &a[minPos]第64行: temp第66行: *x = *y

3、单选题:
‍下面程序中子函数MonthDay()的功能是将某年的第几天转换为某月某日。程序的运行结果如下:‌‍Please enter year, yearDay:2014,100↙‌‍month = 4, day = 10‌‍按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。‌‍‌‍#include    <stdio.h>
void  MonthDay(int year, int yearDay, int *pMonth, int *pDay);
int dayTab[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};

int main()     
{
    int year, month, day, yearDay;
    printf("Please enter year, yearDay:");
    scanf("%d,%d", &year, &yearDay);
    _________________;
    printf("month = %d, day = %dn", month, day); 
    return 0;  
}

/* 函数功能:对给定的某一年的第几天,计算它是这一年的第几月第几日 */
void  MonthDay(int year, int yearDay, int *pMonth, int *pDay)
{  
    int  i, leap;
    leap = _________________________;
    
    for (i=1; yearDay>dayTab[leap][i]; i++)
    {
        yearDay = ______________________;
    }
    ______________;        /* 将计算出的月份值赋值给pMonth所指向的变量 */
    
    *pDay = yearDay;   /* 将计算出的日号赋值给pDay所指向的变量 */
}‌
选项:
A: 第10行: MonthDay(year, yearDay, &month, &day)第19行: ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)第23行: yearDay - dayTab[leap][i]第25行: *pMonth = i
B: 第10行: MonthDay(year, yearDay, month, day)第19行: ((year % 4 == 0) || (year % 100 != 0)) || (year % 400 == 0)第23行: yearDay - dayTab[leap][i]第25行: pMonth = i
C: 第10行: MonthDay(&year, &yearDay, &month, &day)第19行: ((year % 4 == 0) || (year % 100 != 0)) && (year % 400 != 0)第23行: yearDay + dayTab[i][leap]第25行: *pMonth = i
D: 第10行: MonthDay(&year, &yearDay, month, day)第19行: ((year % 4 == 0) && (year % 100 == 0)) || (year % 400 == 0)第23行: yearDay - dayTab[i][leap]第25行: pMonth = i
答案: 【 第10行: MonthDay(year, yearDay, &month, &day)第19行: ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)第23行: yearDay - dayTab[leap][i]第25行: *pMonth = i

4、单选题:
‏子函数Fun的功能是比较形参变量x和y所指的内存单元中的数据大小,将两者中的最小值返回。以下程序执行后输出结果是7,8,7。按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。‎‏#include <stdio.h>
int Fun(int *x,int *y)

    if(___________)  /*如果形参变量x所指的内存单元中的数据小于y所指的内存单元中的数据,则返回该最小值*/
         return *x;
    else
         return *y;
}

int main()

    int a=7,b=8,_______,r;
    p=&a;
    q=&b;
    r=____________;  /*调用子函数Fun,返回变量a和b中的最小值,将其存放到变量r中。*/
    
    printf("%d,%d,%dn",*p,*q,r);
    return 0;
  }‎
选项:
A: 第4行: *x<*y第12行: *p,*q第15行: Fun(p,q)
B: 第4行: x<y第12行: *p,*q第15行: Fun(*p,*q)
C: 第4行: *x<*y第12行: p,q第15行: Fun(&p,&q)
D: 第4行: x<y第12行: *p,*q第15行: Fun(a,b)
答案: 【 第4行: *x<*y第12行: *p,*q第15行: Fun(p,q)

5、单选题:
‏下列函数的功能为________。‏‏void  Exchange(int *p1, int *p2)‏‏{‏‏    int  p;‏‏    p = *p1;‏‏    *p1 = *p2;‏‏    *p2 = p;‏‏}‏
选项:
A: 交换*p1和*p2的值
B: 正确,但无法改变*p1和*p2的值
C: 交换*p1和*p2的地址 
D: 可能造成系统故障
答案: 【 交换*p1和*p2的值

6、单选题:
‍声明语句int (*p)();的含义是________。‏
选项:
A: p是一个指向函数的指针,该函数的返回值是一个整型
B: p是一个指向一维数组的指针变量
C: p是指针变量,指向一个整型数据
D: 以上都不对
答案: 【 p是一个指向函数的指针,该函数的返回值是一个整型

7、单选题:
‏声明语句int *f();中f的含义是________。‎
选项:
A: 一个返回值为指针类型的函数名
B: 一个用于指向函数的指针变量
C: 一个用于指向一维数组的行指针
D: 一个用于指向整型数据的指针变量
答案: 【 一个返回值为指针类型的函数名

8、单选题:
‍下面程序的功能是用函数编程实现两个数组中对应元素值的交换。按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。‍‍程序的运行结果示例:‍‍Input array size(n<=10):5↙‍‍Input array a:1 2 3 4 5↙‍‍Input array b:6 7 8 9 10↙‍‍Output array a:    6    7    8    9   10‍‍Output array b:    1    2    3    4    5‍‍‍‍#include  <stdio.h>
#define N 10
void ReadData(int a[], int n);
void PrintData(int a[], int n);
void Swap(int *x, int *y);
int main()
{
    int  a[N], b[N], i, n;
    printf("Input array size(n<=10):");
    scanf("%d", &n);
    printf("Input array a:");
    ReadData(a, n);
    printf("Input array b:");
    ReadData(b, n);
    for (i=0; i<n; i++)
      {
         Swap(____________);
      }

    printf("Output array a:");
    PrintData(a, n);
    printf("Output array b:");
    PrintData(b, n);
    return 0;
}

/* 函数功能:输入数组a的n个元素值 */
void ReadData(int a[], int n)
{
    int i;
    for (i=0; i<n; i++)
     {
          scanf("%d", &a[i]);
     }
}

/* 函数功能:输出数组a的n个元素值 */
void PrintData(int a[], int n)
{
    int i;
    for (i=0; i<n; i++)
     {
          printf("%5d", a[i]);
     }
    printf("n");
}

/* 函数功能:两整数值互换 */
void  Swap(int *x, int *y)
{
     int  temp;
     ____________;
     ____________;
     ____________;
}‍
选项:
A: 第17行:&a[i], &b[i]第52行:temp = *x第53行:*x = *y第54行:*y = temp
B: 第17行:a[i], b[i]第52行:temp = *x第53行:*x = *y第54行:*y = temp
C: 第17行:&a[i], &b[i]第52行:*temp = *x第53行:*x = *y第54行:*y = *temp
D: 第17行:a[i], b[i]第52行:temp = x第53行:x = y第54行:y = temp
答案: 【 第17行:&a[i], &b[i]第52行:temp = *x第53行:*x = *y第54行:*y = temp

9、单选题:
‏给出下面程序的运行结果。‍‏#include <stdio.h>
int main(void)
{
    static int x[]  =  {1,2,3};
    int  s = 1, i, *p = x; 

    for (i=0; i<3; i++)
    {
        s*= *(p + i);
    }

    printf("%dn", s);
    return 0;
}‍
选项:
A: 6
B: 3
C: 4
D: 5
答案: 【 6

10、单选题:
‌从键盘任意输入10个整数,计算并输出最大值和最小值及其它们在数组中的下标位置。按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。‏‌程序运行结果示例1:‏‌Input 10 numbers:1 2 3 4 5 6 7 8 9 10↙‏‌max=10,pos=9‏‌min=1,pos=0‏‌程序运行结果示例2:‏‌Input 10 numbers:2 4 5 6 8 10 1 3 5 7 9↙‏‌max=10,pos=5‏‌min=1,pos=6‏‌#include <stdio.h>
int FindMax(int a[], int n, int *pMaxPos);
int FindMin(int a[], int n, int *pMinPos);
int main()
{
    int a[10], maxValue, maxPos, minValue, minPos, i;
    printf("Input 10 numbers:");
    for (i=0; i<10; i++)
    {
        scanf("%d", &a[i]);             // 输入10个数
    }

    maxValue = FindMax(a, 10, _________);  // 找最大值及其所在下标位置
    minValue = FindMin(a, 10, _________);  // 找最小值及其所在下标位置
    printf("max=%d,pos=%dn", maxValue, maxPos);
    printf("min=%d,pos=%dn", minValue, minPos);
    return 0;
}

//函数功能:求有n个元素的整型数组a中的最大值及其所在下标位置,函数返回最大值
int FindMax(int a[], int n, int *pMaxPos)
{
    int i, max;
    max = a[0];             //假设a[0]为最大值
    __________;           //假设最大值在数组中的下标位置为0
    
    for (i=1; i<n; i++)
    {
        if (a[i] > max)
        {
            max = a[i];
            __________;     //pMaxPos指向最大值数组元素的下标位置
        }
    }
    return max ;
}

//函数功能:求有n个元素的整型数组a中的最小值及其所在下标位置,函数返回最小值
int FindMin(int a[], int n, int *pMinPos)
{
    int i, min;
    min = a[0];              //假设a[0]为最小
    __________;            //假设最小值在数组中的下标位置为0
    
    for (i=1; i<10; i++)
    {
        if (a[i] < min)
        {
            min = a[i];
            __________;  //pMinPos指向最小值数组元素的下标位置
        }
    }
    return min ;
}‏
选项:
A: 第13行:&maxPos第14行:&minPos第25行:*pMaxPos = 0第32行:*pMaxPos = i第43行:*pMinPos = 0第50行:*pMinPos = i
B: 第13行:maxPos第14行:minPos第25行:pMaxPos = 0第32行:*pMaxPos = i第43行:pMinPos = 0第50行:*pMinPos = i
C: 第13行:maxPos第14行:minPos第25行:pMaxPos = 0第32行:pMaxPos = i第43行:pMinPos = 0第50行:pMinPos = i
D: 第13行:&maxPos第14行:&minPos第25行:pMaxPos = 0第32行:pMaxPos = i第43行:*pMinPos = 0第50行:*pMinPos = i
答案: 【 第13行:&maxPos第14行:&minPos第25行:*pMaxPos = 0第32行:*pMaxPos = i第43行:*pMinPos = 0第50行:*pMinPos = i

11、单选题:

采用梯形法编程实现在积分区间[a,b]内计算下面两个函数定积分。

按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。

程序运行结果示例:

y1=1.333350

y2=1.151212

#include <stdio.h>
float Fun1(float x);
float Fun2(float x);
float Integral(float (*f)(float), float a, float b);
int main()
{
    float y1, y2;
    y1 = Integral(Fun1, 0.0, 1.0);
    y2 = Integral(Fun2, 0.0, 3.0);
    printf("y1=%fny2=%fn", y1, y2);
    return 0;
}

/*  函数功能:计算函数1+x*x的函数值 */
float Fun1(float x)
{
    return  1 + x * x;
}

/*  函数功能:计算函数x/(1+x*x)的函数值 */
float Fun2(float x)
{
    return x / (1 + x * x);
}

/*    函数功能:用梯形法计算函数的定积分 */
float Integral(float (*f)(float), float a, float b)
{
    float s, h;
    int n = 100, i;
    s = __________;
    h = __________;
    
    for (i=1; i<n; i++)
    {
       s += __________;
    }
    return __________;
}

‎选项:
A: 第31行:((*f)(a) + (*f)(b)) / 2第32行:(b - a) / n第36行:(*f)(a + i * h)第38行:s * h
B: 第31行:(*f)(a+b) / 2第32行:(b - a) / n第36行:(*f)(a + i * h)第38行:s 
C: 第31行:((*f)(a) + (*f)(b)) / 2第32行:(a - b) / n第36行:*f(a + i * h)第38行:s * h
D: 第31行:(*f)(a+b) / 2第32行:(a - b) / n第36行:*f(a + i * h)第38行:s
答案: 【 第31行:((*f)(a) + (*f)(b)) / 2第32行:(b - a) / n第36行:(*f)(a + i * h)第38行:s * h

筛法求素数

1、判断题:
‌筛法求素数的核心操作就是在一个按a[2]=2,a[3]=3,......,a[N]=N初始化的数组中依次筛掉所有素数的倍数。‌
选项:
A: 正确
B: 错误
答案: 【 正确

练兵区——单选题——不计入总分

1、单选题:
下面程序的功能是输入某年某月某日,计算并输出它是这一年的第几天。​程序的运行结果如下:​Please enter year, month, day:2014,12,29↙​yearDay = 363​按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。​#include    <stdio.h>
int  DayofYear(int year, int month, int day);
int dayTab[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};
int main()
{
    int year, month, day, yearDay;
    printf("Please enter year, month, day:");
    scanf("%d,%d,%d", &year, &month, &day);
    yearDay = DayofYear(year, month, day);
    printf("yearDay = %dn", yearDay);
    return 0;
}

/* 函数功能:对给定的某年某月某日,计算并返回它是这一年的第几天 */
int  DayofYear(int year, int month, int day)
{
    int  i, leap;
    leap = ________________________;  /* 若year为闰年,即leap值为1,则用第1行元素dayTab[1][i]计算;
                                       否则leap值为0,用第0行dayTab[0][i]计算 */
    for (i=1; _______; i++)
    {
        day = ________________;
    }
    return day;         /* 返回计算出的day的值 */
}
选项:
A: 第18行:  ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)第20:    i<month第22行:  day + dayTab[leap][i]
B: 第18行:  ((year % 4 == 0) || (year % 100 != 0)) || (year % 400 == 0)第20:    i<month第22行:  day + dayTab[i][leap]
C: 第18行:  ((year % 4 == 0) && (year % 100 != 0)) && (year % 400 == 0)第20:    i<12第22行:  day + dayTab[leap][i]
D: 第18行:  ((year % 4 != 0) && (year % 100 != 0)) || (year % 400 != 0)第20:    i<=month第22行:  day + dayTab[i][leap]
答案: 【 第18行:  ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)第20:    i<month第22行:  day + dayTab[leap][i]

2、单选题:
下面程序中子函数MonthDay()的功能是将某年的第几天转换为某月某日。程序的运行结果如下:‍Please enter year, yearDay:2014,100↙‍month = 4, day = 10‍按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。‍#include    <stdio.h>
void  MonthDay(int year, int yearDay, int *pMonth, int *pDay);
int dayTab[2][13] = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};

int main()     
{
    int year, month, day, yearDay;
    printf("Please enter year, yearDay:");
    scanf("%d,%d", &year, &yearDay);
    _________________;
    printf("month = %d, day = %dn", month, day); 
    return 0;  
}

/* 函数功能:对给定的某一年的第几天,计算它是这一年的第几月第几日 */
void  MonthDay(int year, int yearDay, int *pMonth, int *pDay)
{  
    int  i, leap;
    leap = _________________________;
    
    for (i=1; yearDay>dayTab[leap][i]; i++)
    {
        yearDay = ______________________;
    }
    ______________;        /* 将计算出的月份值赋值给pMonth所指向的变量 */
    
    *pDay = yearDay;   /* 将计算出的日号赋值给pDay所指向的变量 */
}
选项:
A: 第10行: MonthDay(year, yearDay, &month, &day)第19行: ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)第23行: yearDay - dayTab[leap][i]第25行: *pMonth = i
B: 第10行: MonthDay(year, yearDay, month, day)第19行: ((year % 4 == 0) || (year % 100 != 0)) || (year % 400 == 0)第23行: yearDay - dayTab[leap][i]第25行: pMonth = i
C: 第10行: MonthDay(&year, &yearDay, &month, &day)第19行: ((year % 4 == 0) || (year % 100 != 0)) && (year % 400 != 0)第23行: yearDay + dayTab[i][leap]第25行: *pMonth = i
D: 第10行: MonthDay(&year, &yearDay, month, day)第19行: ((year % 4 == 0) && (year % 100 == 0)) || (year % 400 == 0)第23行: yearDay - dayTab[i][leap]第25行: pMonth = i
答案: 【 第10行: MonthDay(year, yearDay, &month, &day)第19行: ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)第23行: yearDay - dayTab[leap][i]第25行: *pMonth = i

3、单选题:
‌子函数Fun的功能是比较形参变量x和y所指的内存单元中的数据大小,将两者中的最小值返回。以下程序执行后输出结果是7,8,7。按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求‍#include <stdio.h>
int Fun(int *x,int *y)

    if(___________)  /*如果形参变量x所指的内存单元中的数据小于y所指的内存单元中的数据,则返回该最小值*/
         return *x;
    else
         return *y;
}

int main()

    int a=7,b=8,_______,r;
    p=&a;
    q=&b;
    r=____________;  /*调用子函数Fun,返回变量a和b中的最小值,将其存放到变量r中。*/
    
    printf("%d,%d,%dn",*p,*q,r);
    return 0;
  }
选项:
A: 第4行: *x<*y第12行: *p,*q第15行: Fun(p,q)
B: 第4行: x<y第12行: *p,*q第15行: Fun(*p,*q)
C: 第4行: *x<*y第12行: p,q第15行: Fun(&p,&q)
D: 第4行: x<y第12行: *p,*q第15行: Fun(a,b)
答案: 【 第4行: *x<*y第12行: *p,*q第15行: Fun(p,q)

4、单选题:
下面程序的功能是从键盘输入10个整数,用函数编程实现计算其最大值和最小值,并互换它们所在数组中的位置。程序运行结果如下:‌Input n(n<=10):10↙‌Input 10 Numbers:1 4 3 0 –2 6 7 2 9 -1 ↙‌Exchange results:     1     4     3     0     9     6     7     2    -2    -1‌按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。‌#include  <stdio.h>
void ReadData(int a[], int n);
void PrintData(int a[], int n);
void  MaxMinExchang(int a[], int n);
void Swap(int *x, int *y);
int main()
{
    int  a[10], n;
    printf("Input n(n<=10):");
    scanf("%d", &n);
    printf("Input %d numbers:", n);
    ReadData(a, n); 
    MaxMinExchang(a, n);
    printf("Exchange results:");
    PrintData(a, n); 
    return 0;
}

/* 函数功能:输入数组a的n个元素值 */
void ReadData(int a[], int n)  
{
    int i;
    for (i=0; i<n; i++)
     {
          scanf("%d", &a[i]);
     }
}

/* 函数功能:输出数组a的n个元素值 */
void PrintData(int a[], int n)  
{
    int i;
    for (i=0; i<n; i++)
     {
          printf("%5d", a[i]);
     }
    printf("n");
}

/* 函数功能:将数组a中的最大数与最小数位置互换 */
void  MaxMinExchang(________, int n)
{
    int  maxValue = a[0], minValue = a[0], maxPos = 0, minPos = 0;
    int  i;
    for (i=1; i<n; i++)
    {
        if (a[i] > maxValue)
        {
            maxValue = _______;
            maxPos = ____;
        }
        if (a[i] < minValue)
        {
            minValue = a[i];
            minPos = i;
       }
}
        Swap(________________);
}

/* 函数功能:两整数值互换 */
void  Swap(int *x, int *y)                
{
    int  ________;
    temp = *x;                          
    _________;
                    
    *y = temp;            
}
选项:
A: 第41行: int a[]第49行: a[i]第50行: i第58行: &a[maxPos], &a[minPos]第64行: temp第66行: *x = *y
B: 第41行: int a第49行: a[i]第50行: i第58行: a[maxPos], a[minPos]第64行: temp第66行: *x = *y
C: 第41行: int a[]第49行: a[0]第50行: 0第58行: &a[maxPos], &a[minPos]第64行: *temp第66行: x = y
D: 第41行: int a[]第49行: a[n-1]第50行: n-1第58行: *a[maxPos], *a[minPos]第64行: &temp第66行: x = y
答案: 【 第41行: int a[]第49行: a[i]第50行: i第58行: &a[maxPos], &a[minPos]第64行: temp第66行: *x = *y

5、单选题:
下列函数的功能为________。‍void  Exchange(int *p1, int *p2)‍{‍    int  p;‍    p = *p1;‍    *p1 = *p2;‍    *p2 = p;‍}‍‎‍
选项:
A: 交换*p1和*p2的值
B: 正确,但无法改变*p1和*p2的值
C: 交换*p1和*p2的地址 
D: 可能造成系统故障
答案: 【 交换*p1和*p2的值

6、单选题:
‎声明语句int (*p)();的含义是________。​
选项:
A: p是一个指向函数的指针,该函数的返回值是一个整型
B: p是一个指向一维数组的指针变量
C: p是指针变量,指向一个整型数据
D: 以上都不对
答案: 【 p是一个指向函数的指针,该函数的返回值是一个整型

7、单选题:
‍声明语句int *f();中f的含义是________。‍
选项:
A: 一个返回值为指针类型的函数名
B: 一个用于指向函数的指针变量
C: 一个用于指向一维数组的行指针
D: 一个用于指向整型数据的指针变量
答案: 【 一个返回值为指针类型的函数名

8、单选题:
下面程序的功能是用函数编程实现两个数组中对应元素值的交换。按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。‏程序的运行结果示例:‏Input array size(n<=10):5↙‏Input array a:1 2 3 4 5↙‏Input array b:6 7 8 9 10↙‏Output array a:    6    7    8    9   10‏Output array b:    1    2    3    4    5‏‏#include  <stdio.h>
#define N 10
void ReadData(int a[], int n);
void PrintData(int a[], int n);
void Swap(int *x, int *y);
int main()
{
    int  a[N], b[N], i, n;
    printf("Input array size(n<=10):");
    scanf("%d", &n);
    printf("Input array a:");
    ReadData(a, n);
    printf("Input array b:");
    ReadData(b, n);
    for (i=0; i<n; i++)
      {
         Swap(____________);
      }

    printf("Output array a:");
    PrintData(a, n);
    printf("Output array b:");
    PrintData(b, n);
    return 0;
}

/* 函数功能:输入数组a的n个元素值 */
void ReadData(int a[], int n)
{
    int i;
    for (i=0; i<n; i++)
     {
          scanf("%d", &a[i]);
     }
}

/* 函数功能:输出数组a的n个元素值 */
void PrintData(int a[], int n)
{
    int i;
    for (i=0; i<n; i++)
     {
          printf("%5d", a[i]);
     }
    printf("n");
}

/* 函数功能:两整数值互换 */
void  Swap(int *x, int *y)
{
     int  temp;
     ____________;
     ____________;
     ____________;
}‏‎‏
选项:
A: 第17行:&a[i], &b[i]第52行:temp = *x第53行:*x = *y第54行:*y = temp
B: 第17行:a[i], b[i]第52行:temp = *x第53行:*x = *y第54行:*y = temp
C: 第17行:&a[i], &b[i]第52行:*temp = *x第53行:*x = *y第54行:*y = *temp
D: 第17行:a[i], b[i]第52行:temp = x第53行:x = y第54行:y = temp
答案: 【 第17行:&a[i], &b[i]第52行:temp = *x第53行:*x = *y第54行:*y = temp

9、单选题:
给出下面程序的运行结果。​#include <stdio.h>
int main(void)
{
    static int x[]  =  {1,2,3};
    int  s = 1, i, *p = x; 

    for (i=0; i<3; i++)
    {
        s*= *(p + i);
    }

    printf("%dn", s);
    return 0;
}​‍​
选项:
A: 6
B: 3
C: 4
D: 5
答案: 【 6

10、单选题:
从键盘任意输入10个整数,计算并输出最大值和最小值及其它们在数组中的下标位置。按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。​程序运行结果示例1:​Input 10 numbers:1 2 3 4 5 6 7 8 9 10↙​max=10,pos=9​min=1,pos=0​程序运行结果示例2:​Input 10 numbers:2 4 5 6 8 10 1 3 5 7 9↙​max=10,pos=5​min=1,pos=6​#include <stdio.h>
int FindMax(int a[], int n, int *pMaxPos);
int FindMin(int a[], int n, int *pMinPos);
int main()
{
    int a[10], maxValue, maxPos, minValue, minPos, i;
    printf("Input 10 numbers:");
    for (i=0; i<10; i++)
    {
        scanf("%d", &a[i]);             // 输入10个数
    }

    maxValue = FindMax(a, 10, _________);  // 找最大值及其所在下标位置
    minValue = FindMin(a, 10, _________);  // 找最小值及其所在下标位置
    printf("max=%d,pos=%dn", maxValue, maxPos);
    printf("min=%d,pos=%dn", minValue, minPos);
    return 0;
}

//函数功能:求有n个元素的整型数组a中的最大值及其所在下标位置,函数返回最大值
int FindMax(int a[], int n, int *pMaxPos)
{
    int i, max;
    max = a[0];             //假设a[0]为最大值
    __________;           //假设最大值在数组中的下标位置为0
    
    for (i=1; i<n; i++)
    {
        if (a[i] > max)
        {
            max = a[i];
            __________;     //pMaxPos指向最大值数组元素的下标位置
        }
    }
    return max ;
}

//函数功能:求有n个元素的整型数组a中的最小值及其所在下标位置,函数返回最小值
int FindMin(int a[], int n, int *pMinPos)
{
    int i, min;
    min = a[0];              //假设a[0]为最小
    __________;            //假设最小值在数组中的下标位置为0
    
    for (i=1; i<10; i++)
    {
        if (a[i] < min)
        {
            min = a[i];
            __________;  //pMinPos指向最小值数组元素的下标位置
        }
    }
    return min ;
}​‎​
选项:
A: 第13行:&maxPos第14行:&minPos第25行:*pMaxPos = 0第32行:*pMaxPos = i第43行:*pMinPos = 0第50行:*pMinPos = i
B: 第13行:maxPos第14行:minPos第25行:pMaxPos = 0第32行:*pMaxPos = i第43行:pMinPos = 0第50行:*pMinPos = i
C: 第13行:maxPos第14行:minPos第25行:pMaxPos = 0第32行:pMaxPos = i第43行:pMinPos = 0第50行:pMinPos = i
D: 第13行:&maxPos第14行:&minPos第25行:pMaxPos = 0第32行:pMaxPos = i第43行:*pMinPos = 0第50行:*pMinPos = i
答案: 【 第13行:&maxPos第14行:&minPos第25行:*pMaxPos = 0第32行:*pMaxPos = i第43行:*pMinPos = 0第50行:*pMinPos = i

11、单选题:

采用梯形法编程实现在积分区间[a,b]内计算下面两个函数定积分。

按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。

程序运行结果示例:

y1=1.333350

y2=1.151212

#include <stdio.h>
float Fun1(float x);
float Fun2(float x);
float Integral(float (*f)(float), float a, float b);
int main()
{
    float y1, y2;
    y1 = Integral(Fun1, 0.0, 1.0);
    y2 = Integral(Fun2, 0.0, 3.0);
    printf("y1=%fny2=%fn", y1, y2);
    return 0;
}

/*  函数功能:计算函数1+x*x的函数值 */
float Fun1(float x)
{
    return  1 + x * x;
}

/*  函数功能:计算函数x/(1+x*x)的函数值 */
float Fun2(float x)
{
    return x / (1 + x * x);
}

/*    函数功能:用梯形法计算函数的定积分 */
float Integral(float (*f)(float), float a, float b)
{
    float s, h;
    int n = 100, i;
    s = __________;
    h = __________;
    
    for (i=1; i<n; i++)
    {
       s += __________;
    }
    return __________;
}

‌选项:
A: 第31行:((*f)(a) + (*f)(b)) / 2第32行:(b - a) / n第36行:(*f)(a + i * h)第38行:s * h
B: 第31行:(*f)(a+b) / 2第32行:(b - a) / n第36行:(*f)(a + i * h)第38行:s 
C: 第31行:((*f)(a) + (*f)(b)) / 2第32行:(a - b) / n第36行:*f(a + i * h)第38行:s * h
D: 第31行:(*f)(a+b) / 2第32行:(a - b) / n第36行:*f(a + i * h)第38行:s
答案: 【 第31行:((*f)(a) + (*f)(b)) / 2第32行:(b - a) / n第36行:(*f)(a + i * h)第38行:s * h

随机生成一个各位相异的4位数

1、判断题:
‌void MakeDigit(int a[])
{
  int i, j, temp;
  srand(time(NULL));  
  for (i=0; i<10; i++)
  {
  a[i] = i;
  }
  for (i=0; i<10; i++)
  {
  j = rand() % 10;
  temp = a[j];
  a[j] = a[i];
  a[i] = temp;
  }
}这个方法其实就是模拟了洗牌的方法对一个有序的数组元素进行随机置乱。‍‌‍
选项:
A: 正确
B: 错误
答案: 【 正确

第2周——指针与数组

元素在二维数组中相对于首地址的偏移量

1、单选题:
‏二维数组a有m行n列,则在a[i][j]之前的元素个数为()‍
选项:
A: j*n+i  
B: i*n+j
C: i*n+j-1
D: i*n+j+1
答案: 【 i*n+j

字符指针数组

1、判断题:
‎char *country[] = {"America", "England", "Australia", "China", "Finland"};‍‎这条语句定义了一个字符指针数组country,并用初始化列表中的每个字符串的首地址为字符指针数组country的元素进行初始化,并不是将初始化列表中的字符串保存到字符指针数组中。‍
选项:
A: 正确
B: 错误
答案: 【 正确

指针和一维数组

1、判断题:
​当指针变量指向一维数组的时候,sizeof(数组名)和sizeof(指针变量名)的计算结果是相同的。​
选项:
A: 正确
B: 错误
答案: 【 错误

指针的算术运算

1、单选题:
‏下列说法错误的是()。‎
选项:
A: 指针指向数组元素时,指针算术运算才有意义
B: 两个指针指向同一个数组时,指针相减才有意义
C: 指针的算术运算允许通过对指针变量重复自增来访问数组的元素
D: p++就是将指针变量p加上一个字节
答案: 【 p++就是将指针变量p加上一个字节

第10周课堂测验1-2

1、单选题:
‍下面程序的功能是用指针变量作函数参数编程计算任意m×n阶矩阵的转置矩阵。要求用指向一维数组的指针变量即二维数组的行指针作函数参数。程序的运行结果如下:​‍Please enter matrix:​‍1 2 3 4↙​‍1 2 3 4↙​‍1 2 3 4↙​‍The transposed matrix is:​‍1    1    1​‍2    2    2​‍3    3    3​‍4    4    4​‍按要求在空白处填写适当的表达式或语句,使程序完整并符合题目要求。​‍#include <stdio.h>
#define ROW 3
#define COL 4
void Transpose(int (*a)[COL], int (*at)[ROW], int row, int col);  
void InputMatrix(int (*s)[COL], int row, int col);    
void PrintMatrix(int (*s)[ROW], int row, int col);    
int main(void)
{
    int s[ROW][COL];//s代表原矩阵
    int st[COL][ROW];//st代表转置后的矩阵
    printf("Please enter matrix:n");
    InputMatrix(s, ROW, COL);//输入原矩阵,s指向矩阵s的第0行,是行指针
    Transpose(s, st, ROW, COL);//对矩阵s进行转置,结果存放于st中  
    printf("The transposed matrix is:n");
    PrintMatrix(st, COL, ROW); //输出转置矩阵,*st指向st的第0行,是行指针
    return 0;
}

//函数功能: 对任意row行col列的矩阵a转置,转置后的矩阵为at
void Transpose(____________,int (*at)[ROW], int row, int col)   

    int i, j;
    for (i=0; i<row; i++)
    {
        for (j=0; j<col; j++)
        {
            _____________________;   
        }
    }
}

void InputMatrix(___________, int row, int col)   //输入矩阵元素
{
    int i, j;
    for (i=0; i<row; i++)
    {
        for (j=0; j<col; j++)
        {
            scanf("%d", ___________);// 元素s[i][j]
        }
    }
}

void PrintMatrix(int ___________, int row, int col)   //输出矩阵元素
{
    int i, j;
    for (i=0; i<row; i++)
    {
        for (j=0; j<col; j++)
        {
            printf("%dt", *(*(s+i)+j)); // 元素s[i][j]
        }
        printf(" n");
    }
}​
选项:
A: 第20行:  int (*a)[COL]第27行:  *(*(at+j)+i) = *(*(a+i)+j)第32行:  int(*s)[COL]第39行:  *(s+i)+j第44行:  (*s)[ROW]
B: 第20行:  int *a[COL]第27行:  *(*(at+j)+i) = (*(a+i)+j)第32行:  int(*s)[ROW]第39行:  *(s+i)+j第44行:  *s[COL]
C: 第20行:  int (*a)[ROW]第27行:  *(at+j+i) = *(*(a+i)+j)第32行:  int(*s)[COL]第39行:  *(s+i+j)第44行:  (*s)[ROW]
D: 第20行:  int (*a)[COL]第27行:  *(*(at+j)+i) = *(*(a+i+j))第32行:  int(*s)[ROW]第39行:  *(s)+i+j第44行:  (*s)[COL]
答案: 【 第20行:  int (*a)[COL]第27行:  *(*(at+j)+i) = *(*(a+i)+j)第32行:  int(*s)[COL]第39行:  *(s+i)+j第44行:  (*s)[ROW]

2、单选题:

剩余75%内容付费后可查看

发表评论

电子邮件地址不会被公开。 必填项已用*标注