• —四川最大高校综合门户网
  • 用户名: 密码: 验证码: 注册会员写作
  • 首页
  • 家教
  • 校园
  • 学习
  • 论文
  • 考试
  • 考研
  • 英语
  • 读书
  • 留学
  • 实习
  • 招聘
  • 求职
  • 创业
  • 高考
  • 大赛
  • 专题
  • 交友
  • 日记
  • 相册
  • 壁纸
  • 图库
  • 两性
  • flash
  • 笑话
  • 闪字
  • 培训
  • 商城
  • 电影
  • 音乐
  • 分类
  • 问答
  • 圈子
  • 查询
  • 顶客
  • 社区
  • 您所在的位置:四川大学生联盟 > 考研 > 历年试题 > 吉林地区考研试卷 > 吉林大学2004年硕士研究生入学考试C语言试卷
  • 吉林大学2004年硕士研究生入学考试C语言试卷

    时间:2008-02-16 点击: 收藏 评论 0 条 我要投稿
    相关热点: 考试 语言 试卷 入学 研究生 大学 硕士 head pointer
    本文摘要:

    /*===========================================================================*/ /*程序名称:2004_1.c */ /*程序目的:计算一个“零幺串”当中最长的零/幺串 */ /*Writen by Apechn ,Soft Lab of JLU*/ /*======================================================


    /*===========================================================================*/
    /*程序名称:2004_1.c                                                         */
    /*程序目的:计算一个“零幺串”当中最长的零/幺串                             */
    /*Writen by Apechn ,Soft Lab of JLU                                          */
    /*===========================================================================*/#include <stdio.h>#define MAX 100void main(void){ char s[MAX]; /* 用来保存用户输入的"零/幺串" */ int i = 0;   /* 计数器 */ int n0 = 0; /* 保存最长"零串"数0的个数 */ int n1 = 0;  /* 保存最长"幺串"中1的个数 */ int temp0 = 0,temp1 = 0; printf("请输入一个仅由0/1组成的字符串:/n"); scanf("%s",s);  /* 由用户输入"零幺串" */ while (s[i]) {  if (s[i] == '0')   temp0++;  if (temp0 > n0) /* n0取已经扫描过的"零串"中0个数最多者 */  {   n0 = temp0;   temp1 = 0; /* 处理"零串"时将"幺串"计数的临时变量置零 */  }  if (s[i] == '1')   temp1++;  if (temp1 > n1) /* n1取已经扫描过的"零串"中1个数最多者 */  {   n1 = temp1;   temp0 = 0; /* 处理"幺串"时将"零串"计数的临时变量置零 */  }  i++; } printf("最长的/"零串/"中零的个数即n0 = %d ./n",n0); /* 输出结果 */ printf("最长的/"幺串/"中幺的个数即n1 = %d ./n",n1);}

    考研试题
    /*====================================================================================*/
    /*程序名称:2004_2.c                                             */
    /*程序目的:两个多项式相加                                           */
    /*Writen by Apechn ,Soft Lab of JLU                                    */
    /*====================================================================================*/
    #include <stdio.h>
    #include <stdlib.h>
    struct list     /* 节点结构声明 */
    {
    int power;    /* 多项式中变量的幂 */
    int coeff;    /* 多项式中变量的系数 */
    struct list *next;
    };
    typedef struct list node;
    typedef node *poly;
    /*-------------------------------------*/
    /* 打印出一个多项式的各项       */
    /*-------------------------------------*/
    void printPoly(poly head)
    {
    poly pointer;    /* 临时指针变量 */
    pointer = head;
    while (pointer != NULL)  /* 打印各节点 */
    {
      printf("[%d,%d] ",pointer->coeff,pointer->power);
      
      pointer = pointer->next;
    }
    printf("/n");
    }
    /*------------------------------------------------------------------------------*/
    /* 从键盘输入一个多项式的项数和各项的幂和系数,多项式的系数不能为零       */
    /*------------------------------------------------------------------------------*/
    poly createPoly(poly head) /* 从键盘输入一个多项式的项数和各项的幂和系数 */
    {
    poly newNode;     /* 临时节点 */
    poly pointer;
    int n,i;
    int coeffTemp,powerTemp;   /* 临时变量 */
    head = (poly) malloc(sizeof(node));  /* 内存配置 */
    if (head == NULL)
      printf("Memory allocate Failure!!/n"); /* 内存配置失败 */
    else
    {
      printf("请输入要创建的多项式的项数:/n");
      scanf("%d",&n);
      if (n == 0)
       return NULL;
      printf("请按x降幂依次输入各项的系数和幂:/n");
      
      scanf("%d%d",&coeffTemp,&powerTemp);/* 输入多项式一项的系数和幂 */
      head->coeff = coeffTemp;      /* 定义首节点 */
      head->power = powerTemp;
      head->next = NULL;
      
      pointer = head;
      for (i = 1;i < n;i++)   /* 依次定义其它节点 */
      {
       scanf("%d%d",&coeffTemp,&powerTemp); /* 输入各项的系数和幂 */
       newNode = (poly) malloc(sizeof(node));
       newNode->coeff = coeffTemp;
       newNode->power = powerTemp;
       newNode->next = NULL;
       pointer->next = newNode;  /* 将新定义的节点连接到原链表的表尾 */
       pointer = newNode;   /* pointer指针后移 */
      }
    }
    printPoly(head);
    return head;
    }

    /*-----------------------------------*/
    /* 释放一个链表的空间                */
    /*-----------------------------------*/
    void freeList(poly head)
    {
    poly pointer; /* 临时指针变量 */
    while (head != NULL)
    {
      pointer = head;
      head = head->next;
      free(pointer);
    }
    }
    /*--------------------------------------------*/
    /* 计算两个多项式的和,并将结果存入另一个链表 */
    /*--------------------------------------------*/
    poly addPoly(poly head1,poly head2)
    {
    poly pointer1,pointer2,pointer,newNode,head;/* 临时指针变量 */
    pointer1 = head1;
    pointer2 = head2;
    head = (poly) malloc(sizeof(node));
    pointer = head;
    while ((pointer1 != NULL) || (pointer2 != NULL)) /* 若两个多项式至少有一个没有访问结束 */
    {
      if (pointer1 !=NULL && pointer2 != NULL &&(pointer1->power > pointer2->power))
      {/* 若两个多项式当前指针指向的项的幂不相等 */
       newNode = (poly) malloc(sizeof(node));
       newNode->power = pointer1->power;
       newNode->coeff = pointer1->coeff;
       newNode->next = NULL;
      
       pointer->next = newNode;
       pointer = newNode;
       pointer1 = pointer1->next;
      }
      if (pointer1 !=NULL && pointer2 != NULL &&(pointer1->power < pointer2->power))
      {/* 若两个多项式当前指针指向的项的幂不相等 */
       newNode = (poly) malloc(sizeof(node));
       newNode->power = pointer2->power;
       newNode->coeff = pointer2->coeff;
       newNode->next = NULL;
       pointer->next = newNode;
       pointer = newNode;/* 指向存储结果的链表的指针后移 */
       pointer2 = pointer2->next;
      }
      if (pointer1 !=NULL && pointer2 != NULL &&(pointer1->power == pointer2->power))
      {     /* 若两个多项式当前指针指向的项的幂相等 */
       newNode = (poly) malloc(sizeof(node));
       newNode->power = pointer1->power;
       newNode->coeff = pointer1->coeff + pointer2->coeff;
       newNode->next = NULL;
       pointer->next = newNode;
       pointer = newNode;/* 指向存储结果的链表的指针后移 */
      
       pointer1 = pointer1->next;
       pointer2 = pointer2->next;
      }
      if (pointer1 == NULL && pointer2 != NULL)
      {
       newNode = (poly) malloc(sizeof(node));
       newNode->power = pointer2->power;
       newNode->coeff = pointer2->coeff;
       newNode->next = NULL;
       pointer->next = newNode;
       pointer = newNode;/* 指向存储结果的链表的指针后移 */
       pointer2 = pointer2->next;  
      }
      if (pointer2 == NULL && pointer1 != NULL)
      {
       newNode = (poly) malloc(sizeof(node));
       newNode->power = pointer1->power;
       newNode->coeff = pointer1->coeff;
       newNode->next = NULL;
      
       pointer->next = newNode;
       pointer = newNode;
       pointer1 = pointer1->next;
      }
    }

    pointer = head;   /* 由于多用了一个节点,这3行代码将多出的节点释放 */
    head = head->next;
    free(pointer);
    return (head);
    }
    /*------------------------------------------------------------------------------*/
    /* 主程序                                                     */
    /*------------------------------------------------------------------------------*/
    void main()
    {
    poly p,q,r;   /* 定义三个代表多项式的链表 */
    printf("这是多项式p:/n"); /* 创建多项式p */
    p = createPoly(p);
    printf("这是多项式q:/n"); /* 创建多项式q */
    q = createPoly(q);
    r = (poly) malloc(sizeof(node));
    printf("这是多项式p与多项式q的和r:/n");
    r = addPoly(p,q);   /* 将多项式p和多项式q的和赋值给r */
    printPoly(r);
    freeList(p);    /* 释放程序中使用过的链表所占用的空间 */
    freeList(q);
    freeList(r);
    }

    考研试题
    /*=============================================================================*/
    /*程序名称:2004_3.c                                                           */
    /*程序目的:求sin(x)的近似值                                                   */
    /*Writen by Apechn ,Soft Lab of JLU                                            */
    /*=============================================================================*/
    #include <stdio.h>
    #include <stdlib.h>
    #define MIN 0.00005    /* 设置运算停止条件 */
    /*------------------------------------------------------------------------------*/
    /* 计算弧度数为angle的角的正弦值第i项                                           */
    /*------------------------------------------------------------------------------*/
    float spill(int i,float angle)   /* 计算第i项 */
    {
    int symbol,j;    
    float temp = angle;   /* 临时变量 */
      
    if (i % 2)    /* 设置该项的符号 */
      symbol = 1;
    else
      symbol = -1;

    if (i == 1)    /* 若只需要计算一项,直接返回角度值 */
      return (angle);

    for (j = 2;j <= i;j++)   /* 循环计算一项的值 */
    {
      temp *= angle * angle / ((2 * j - 2) * (2 * j - 1));
    }
    temp *= symbol;
    return (temp);
    }
    /*------------------------------------------------------------------------------*/
    /* 递归求解sin(angle)的近似值,其中angle表示用户输入的弧度值                     */
    /*------------------------------------------------------------------------------*/
    float f(int i,float angle)
    {
    float temp;   /* 临时变量 */
    if (i == 1)    /* 递归出口 */
      return angle;
    temp = spill(i,angle);   /* 需要加上的项 */
    return (f((i - 1),angle) + temp);  /* 递归运算 */
    }
    /*------------------------------------------------------------------------------*/
    /* 计算需要的级数的项数,其中angle表示用户输入的弧度值                          */
    /*------------------------------------------------------------------------------*/
    int loopTime(float angle)
    {
    int i = 1;
    float seed = angle;    /* 临时变量 */
    while ((seed >= MIN) || (seed <= (-1 * MIN))) /* 循环条件 */
    {
      i++;
      seed *= angle * angle /((2 * i -1) * (2 * i - 2)) * (-1);
    }
    return i;
    }
    /*------------------------------------------------------------------------------*/
    /* 主程序                                                     */
    /*------------------------------------------------------------------------------*/
    void main()
    {
    float x;     /* 用来保存用户输入的弧度数 */
    int count = 1;    /* 用来保存需要递归的次数 */
    float sinOfAngle = 0;   /* 用来保存最终结果 */
    printf("请输入一个浮点数,它代表一个弧度值:");
    scanf("%f",&x);   /* 用户从键盘输入一个弧度数 */
    count = loopTime(x);
    sinOfAngle = f(count,x);
    printf("sin %f 的近似值为 %f./n",x,sinOfAngle); /* 在屏幕上打印出最终结果 */
    }

    考研试题
    /*=============================================================================*/
    /*函数名称:2004_4.c                                                           */
    /*函数目的:递归的求出一个给定结构树的高度、节点数和路径个数           */
    /*Writen by Siyee ,Soft Lab of JLU                                             */
    /*=============================================================================*/
    int depth = 0;    /* 用来保存深度的变量 */
    void H(tree *T, int *h, int *n, int *k)
    {
    ++*n;
    ++depth;
    *h = max(*h, depth);  /* 如果h比depth小,则更新h */
    if(T->kind=='two'){  /* 若节点有两个子节点 */
      H(T->son1, h, n, k); /* 递归计算两个子节点 */
      H(T->son2, h, n, k);
    }
    else if(T->kind=='one'){ /* 若节点有一个子节点 */
      H(T->son, h, n, k); /* 递归计算这一个子节点 */
    }
    else{
      ++*k;   /* 如果是叶节点,则路径数k增一 */
    }
    --depth;    /* 回溯,深度减一 */
    }

    考研试题
    /*=============================================================================*/
    /*程序名称:2004_5.c                                                           */
    /*程序目的:删除整数单链表中重复的节点                                      */
    /*Writen by Apechn ,Soft Lab of JLU                                            */
    /*=============================================================================*/
    #include <stdio.h>
    #include <stdlib.h>
    #define  N 6    /* 节点个数 */
    struct list      /* 节点结构声明 */
    {
    int number;
    struct list *next;
    };
    typedef struct list node;
    typedef node *link;
    int data[N] = {0,3,0,3,1,3};   /* 输入数据 */
    /*------------------------------------------------------------------------------*/
    /* 以已有的数组为基础建立单链表                                          */
    /*------------------------------------------------------------------------------*/
    link createList(link head)
    {
    link newNode;
    link pointer;    /* 函数中需要用到的临时变量 */
    int i;
    head = (link) malloc(sizeof(node));
    if (head == NULL)   /* 若分配内存失败 */
      printf("Memory allocate Failure!!/n");
    else
    {
      head->number = data[0];   /* 设置首节点 */
      head->next = NULL;
      pointer = head;
      for (i = 1;i < N;i++)   /* 依次设置其它节点 */
      {
       newNode = (link) malloc(sizeof(node));
       newNode->number = data[i];
       newNode->next = NULL;
      
       pointer->next = newNode;
       pointer = newNode;
      }
    }
    return head;
    }
    /*------------------------------------------------------------------------------*/
    /* 递归地删除链表中的重复节点                                            */
    /*------------------------------------------------------------------------------*/
    link delSame(link head)
    {
    link pointer,temp = head;  /* 函数中需要用到的临时变量 */
    if (head->next == NULL)   /* 若head为空则直接返回 */
      return head;
    head->next = delSame(head->next); /* 递归地删除重复节点 */
    pointer = head->next;
    while (pointer != NULL)
    {
      if (head->number == pointer->number) /* 删除重复节点 */
      {
       temp->next = pointer->next;
       free(pointer);   /* 释放被删除节点所占用的空间 */
       pointer = temp->next;
      }
      else
      {
       pointer = pointer->next; /* 如果没有重复节点则指针后移 */
       temp = temp->next;
      }
    }
    return head;
    }
    /*------------------------------------------------------------------------------*/
    /* 释放链表所占用的空间                                                  */
    /*------------------------------------------------------------------------------*/
    void freeList(link head)    
    {
    link pointer;     /* 临时变量 */
    while (head != NULL)
    {
      pointer = head;
      head = head->next;
      free(pointer);    /* 一次释放一个节点所占的空间 */
    }
    }
    /*------------------------------------------------------------------------------*/
    /* 打印链表各项                                                                 */
    /*------------------------------------------------------------------------------*/
    void printList(link head)
    {
    link pointer;     /* 临时变量 */
    pointer = head;
    while (pointer != NULL)
    {
      printf("%d ",pointer->number);
      pointer = pointer->next;
    }
    printf("/n");
    }
    /*------------------------------------------------------------------------------*/
    /* 主程序                                                                       */
    /*------------------------------------------------------------------------------*/
    void main()
    {
    link head;
    link pointer;
    head = createList(head);  /* 以已有的数组为基础建立一个链表 */
    if (head != NULL)    /* 打印未删除重复节点前的数组 */
    {
      printf("初始链表中各元素依次如下所示:/n");
      printList(head);
    }
    pointer = delSame(head);  /* 递归地删除链表中的重复节点 */
    printf("删除重复节点后的链表中各元素依次如下所示:/n");
    printList(pointer);    /* 打印删除重复节点后的数组 */
    freeList(head);
    }


    0
    顶一下
    上一篇:吉林大学2000年硕士研究生入学考试行政管理学(含管理心理学)
    下一篇:吉林大学2003年硕士研究生入学考试宪法试卷
    责任编辑:战国狂
    • Google
    相关文章
    • [吉林地区考研试卷]东北师范大学2002年硕士研
    • [吉林地区考研试卷]东北师范大学2002年硕士研
    • [吉林地区考研试卷]东北师范大学2002年硕士研
    • [吉林地区考研试卷]东北师范大学2002年硕士研
    • [吉林地区考研试卷]东北师范大学2002年硕士研
    • [吉林地区考研试卷]东北师范大学2002年硕士研
    • [吉林地区考研试卷]东北师范大学2004年硕士研
    • [吉林地区考研试卷]东北师范大学2005年硕士研
    • [吉林地区考研试卷]东北师范大学1998年硕士研
    • [吉林地区考研试卷]东北师范大学1998年硕士研
    最新热门图片
    20秒注册会员,你也可以成写手 你的文章也精彩
    • 吉林大学2000年硕士研究生入学考试C语言程序设计
      吉林大学2000年硕士
    • 吉林大学2000年硕士研究生入学考试无机化学(含分析化学)
      吉林大学2000年硕士
    • 吉林大学2001年硕士研究生入学考试C语言程序设计
      吉林大学2001年硕士
    • 吉林大学2001年硕士研究生入学考试计算机综合
      吉林大学2001年硕士
    • 吉林大学2001年硕士研究生入学考试无机化学(含分析化学)
      吉林大学2001年硕士
    • 吉林大学2001年硕士研究生入学考试有机化学
      吉林大学2001年硕士
    • 吉林大学2002年硕士研究生入学考试无机化学(含分析化学)
      吉林大学2002年硕士
    • 吉林大学2002年硕士研究生入学考试有机化学
      吉林大学2002年硕士
    网友热评 共有 0 位网友发表了评论
    查看所有评论
    • 发表评论:(不能超过250字,需审核,请自觉遵守互联网相关政策法规。)
    • 用户名: 密码: 匿名? 注册
    • 请您注意:1.遵守国家有关法律法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任 2.您发表的文章仅代表个人观点 3.四川大学生联盟拥有管理笔名和留言的一切权利
  • 【四川地区考研试卷】 【北京地区考研试卷】 【上海地区考研试卷】 【江苏地区考研试卷】 【天津地区考研试卷】 【重庆地区考研试卷】 【浙江地区考研试卷】 【湖北地区考研试卷】 【湖南地区考研试卷】 【陕西地区考研试卷】 【福建地区考研试卷】 【安徽地区考研试卷】 【山东地区考研试卷】 【广东地区考研试卷】 【吉林地区考研试卷】 【黑龙江地区考研试卷】 【辽宁地区考研试卷】 【甘肃地区考研试卷】
    最新TAGS
    与众不同! 艺术专业 石材养护 倒叙 百万富翁 川内四校 八大原则 作文题 骗入 英语策略调整 沈阳拓展训练 外国留学生 成都户口办理 爆光 信息科学 浙工大 阅读理解B部 乱 一审被判 管理员 沈殿霞 现代 不做处女 全国公共英语三级 礼仪 驾校 同济大学 招生破万人 08秋季 一朵白玫瑰 备战建议 国足 夏令营 九心态 改革开放 偷期末试卷 外墙清洗 昆明 失实 披露
    随机推荐
    吉林大学2002年硕士研究
    吉林大学2000年硕士研究
    东北师范大学1998年硕士
    吉林大学2003年硕士研究
    吉林大学2000年硕士研究
    吉林大学2002年硕士研究
    吉林大学1994年硕士研究
    吉林大学2002年硕士研究
    吉林大学2003年硕士研究
    东北师范大学1998年硕士
    吉林大学1997年硕士研究
    吉林大学1997年硕士研究
    吉林大学2003年硕士研究
    吉林大学2002年硕士研究
    吉林大学1999年硕士研究
    吉林大学1999年硕士研究
    吉林大学2003年硕士研究
    吉林大学1994年硕士研究
    吉林大学2001年硕士研究
    吉林大学2002年硕士研究
    最新热门
    吉林大学2003年硕士研究生入学考试分析化学(含仪器分析)
    吉林大学2003年硕士
    吉林大学2004年硕士研究生入学考试理论力学
    吉林大学2004年硕士
    吉林大学2003年硕士
    吉林大学2000年硕士
    吉林大学2003年硕士
    吉林大学2004年硕士
    吉林大学2004年硕士
    吉林大学2004年硕士
    东北师范大学1998年
    东北师范大学2002年
    吉林大学2001年硕士
    吉林大学2001年硕士
[关于我们]  [网络合作]  [广告服务]  [网站记事]  [联系我们]  [网站地图]
四川大学生联盟 蜀ICP备05017152号 Copyright © 2001-2007 All Rights Reserved.