现在的位置: 首页 > 14 二级C语言 > 正文

2011年9月全国二级C上机真题第7~8套

2013年02月25日 14 二级C语言 ⁄ 共 1473字 ⁄ 字号 暂无评论

【程序填空题_8】给定程序中,函数fun的功能是:计算下式前n项的和和作为函数值返回。
例如,当形参n的值为10时,函数返回:-0.204491

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include  <stdio.h>
#define    N    5
typedef struct  student {
    long  sno;
    char  name[10];
    float  score[3];
} STU;
 
void fun(char  *filename, STU  n)
{
    FILE  *fp;
    /**********found**********/
    fp = fopen(__1__, "rb+");
    /**********found**********/
    fseek(__2__, -(long)sizeof(STU), SEEK_END);
    /**********found**********/
    fwrite(&n, sizeof(STU), 1, __3__);
    fclose(fp);
}
 
main()
{
    STU  t[N]= { {10001,"MaChao", 91, 92, 77}, {10002,"CaoKai", 75, 60, 88},
        {10003,"LiSi", 85, 70, 78},    {10004,"FangFang", 90, 82, 87},
        {10005,"ZhangSan", 95, 80, 88}
    };
    STU  n= {10006,"ZhaoSi", 55, 70, 68}, ss[N];
    int  i,j;
    FILE  *fp;
    fp = fopen("student.dat", "wb");
    fwrite(t, sizeof(STU), N, fp);
    fclose(fp);
    fp = fopen("student.dat", "rb");
    fread(ss, sizeof(STU), N, fp);
    fclose(fp);
    printf("\nThe original data :\n\n");
    for (j=0; j<N; j++) {
        printf("\nNo: %ld  Name: %-8s      Scores:  ",ss[j].sno, ss[j].name);
        for (i=0; i<3; i++)  printf("%6.2f ", ss[j].score[i]);
        printf("\n");
    }
}

【程序修改题_8】给定程序MODI1.C中函数fun的功能是:判断一个整数是否是素数,若是返回1,否则返回0。
在main()函数中若fun返回1输出YES,若fun返回0输出NO!。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>
typedef  struct  aa {
    int  data;
    struct  aa  *next;
} NODE;
NODE *Creatlink(int  n, int  m)
{
    NODE  *h=NULL, *p, *s;
    int  i;
    /**********found***********/
    p=(NODE )malloc(sizeof(NODE));
    h=p;
    p->next=NULL;
    for(i=1; i<=n; i++) {
        s=(NODE *)malloc(sizeof(NODE));
        s->data=rand()%m;
        s->next=p->next;
        p->next=s;
        p=p->next;
    }
    /**********found***********/
    return  p;
}
outlink(NODE  *h)
{
    NODE  *p;
    p=h->next;
    printf("\n\nTHE  LIST :\n\n  HEAD ");
    while(p) {
        printf("->%d ",p->data);
        p=p->next;
    }
    printf("\n");
}
 
main()
{
    NODE  *head;
    head=Creatlink(8,22);
    outlink(head);
}

【程序设计题_8】请编写函数fun,它的功能是:找出一维整型数组元素中最大的值和它所在的下标,最大的值和它所在的下标通过形参传回。数组元素中的值已在主函数中赋予。
主函数中x是数组名,n是x中的数据个数,max存放最大值,index存放最大值所在元素的下标。

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <string.h>
#define    N   80
int  fun( char  *s)
{    
 
}
main()
{  char  line[N];    int  num=0;
   printf("Enter a string :\n"); gets(line);
   num=fun(line);
   printf("The number of word is  :  %d\n\n",num);
}

抱歉!评论已关闭.