| 网站首页 | 考研信息中心 | 考研资料下载 | 考研论坛 | 考研专业试题 | 2008考研招生简章 | 考研图书 | 留言板 | 考研图片中心 | 

设为首页
加入收藏
联系我们

您现在的位置: 考研信息网 >> 考研信息中心 >> 考研资料 >> 免费试卷 >> 东北院校 >> 吉林大学 >> 正文 用户登录 新用户注册
吉林大学2003年硕士研究生入学考试c语言程序设计答案          【字体:
吉林大学2003年硕士研究生入学考试c语言程序设计答案
作者:吉林大学…    文章来源:吉林大学2003年硕士研究生入学考试c语言程序设计答案    点击数:    更新时间:2006-2-17

本站推荐Firefox浏览器,有效阻止病毒和垃圾弹出[正版免费下载]

吉林大学2003年硕士研究生入学考试c语言程序设计答案

2003-1/*====================================================================================*/
/*函数名称:2003_1.c                                  */
/*程序目的:将由整数构成的n(n≥2)阶方阵A就地按顺时针方向旋转90度           */
/*Writen by Apechn ,Soft Lab of JLU                          */
/*====================================================================================*/
#include <stdio.h>
const int N = 9;
void main()
{
 int a[N][N];
 int i,j,temp = 1,x = 0,y = N;
 for (i = 0;i<N;i++) //赋初值
  for (j = 0;j<N;j++)
  {
   a[i][j] = temp;
   temp++;
  }
 for (i = 0;i<N-1;i++) //核心部分
 {
  for (j = x;j<y-1;j++) //根据题目要求,设计出如下几条地址变换规律
  {
   temp = a[i][j];
   a[i][j] = a[N-j-1][i];
   a[N-j-1][i] = a[N-i-1][N-j-1];
   a[N-i-1][N-j-1] = a[j][N-i-1];
   a[j][N-i-1] = temp;
  }
  x++;
  y--;
 }
 for (i = 0;i<N;i++)
 for (j = 0;j<N;j++)
 printf("%d ",a[i][j]);
}
2003-2/*====================================================================================*/
/*函数名称:2003_2.c                                  */
/*程序目的:将一个实数分解为它的整数和小数部分                     */
/*Writen by Apechn ,Soft Lab of JLU                          */
/*====================================================================================*/
#include <stdio.h>
#define GET_ZHENGSHU 0; //宏定义,便于使用
#define GET_XIAOSHU 1
float fun(float f,int sign);
void main()
{
  float a;
  printf("Please input a:");
  scanf("%f",&a);
  printf("整数部分为:%f\n",fun(a,GET_ZHENGSHU));//取整数的使用方法
  printf("小数部分为:%f\n",fun(a,GET_XIAOSHU)); //取小数的使用方法
}
float fun(float f,int sign)
{
  float a = 0;
  if (f>=0)
  {
   while (a<=f) //枚举
      a = a + 1;
   a = a - 1;
  }
  else
  {
   while (a>=f) //枚举
      a = a - 1;
   a = a + 1;
  }
  if (sign == 0)
   return a;
  else
   return (f - a);
}
2003-3/*====================================================================================*/
/*函数名称:2003_3.c                                  */
/*程序目的:对于0<x<1,利用Talor公式,求e^x的近似值,结果精确到10^-8           */
/*Writen by Apechn ,Soft Lab of JLU                          */
/*====================================================================================*/
#include <stdio.h>
#include <math.h>
double e(int x);
void main()
{
  int x;
  printf("Please input x: ");
  scanf("%d",&x);
  printf("\n The result is :%15.8f",e(x));
}
double e(int x)
{
  double result1,result2;
  double c = 1; //除数
  double b = x; //被除数
  int m = 1;
  result1 = 1 + x;
  result2 = 1;
  while (fabs(result1 - result2) >= 1E-8) //控制精确度
  {
   m++;
   c = c * m;
   b = b * x;
   result2 = result1;
   result1 = result1 + b/c;
  }
  return result1;
}
2003-4/*====================================================================================*/
/*函数名称:2003_4.c                                  */
/*程序目的:从输入的字符串中翻译并输出符合该句法的一个数                */
/*Writen by Apechn ,Soft Lab of JLU                          */
/*====================================================================================*/
#include <stdio.h>
#include <math.h>
int isdigtal(char c);
int todig(char c);
void compile(char* str);
void main()
{
  char str[40];
  printf("Please input a string: ");
  scanf("%s",str);
  compile(str);
}
void compile(char* str)
{
  double num = 0;
  int sign = 0,exp = 0;
  char *p = str,c;
  c = *p;
  while (c != '\0')
  {
    if (isdigtal(c)) //如果c是数字
    {
      switch(sign)
      {
        case 0:
          sign = 1;
          num = todig(c);
          break;
        case 1:
          num = num * 10 + todig(c);
          break;
        case 2:
          num = num + todig(c) * pow(10,exp);
          exp--;
          break;
       }
    }
    else if (c == '.') //如果c是小数点
    {
      if (sign == 1)
      {
        sign = 2;
        exp = -1;
      }
    }
    else //如果c是其它字符
    {
      if (sign != 0)
      {
        printf("the number is :%f\n",num);
        return;
      }
    }
    p = p + 1;
    c = *p;
  }
  printf("the number is :%f\n",num);
}
2003-5/*====================================================================================*/
/*函数名称:2003_5.c                                  */
/*程序目的:将递归函数转化为非递归函数                         */
/*Writen by Apechn ,Soft Lab of JLU                          */
/*====================================================================================*/
float f1(float x,float y)
{
  if (x<0)
    return x+y;
  return f1(x-1,x+y) + x/y;
}
float f2(float x,float y)
{
  float result,a,b;
  if (x<0)
    return x+y;
  result = x/y;
  a = x;
  b = y;
  while (a>=0)
  {
    b = a + b;
    a = a - 1;
    result = result + a/b;
  }
  result = result + (a + b);
  return result;
}
2003-6/*=============================================================================*/
/*程序名称:2003_6.c                              */
/*程序目的:从已知二叉树的前序和中序序列构造该二叉树              */
/*Writen by Apechn ,Soft Lab of JLU                       */
/*=============================================================================*/
#include <stdio.h>
struct node //定义链表结点结构,在最前面给出
{
 int data;
 node *left;
 node *right;
}
node *bintree(int i,j,u,v;node *s)
{
 int k,l;
 s = NULL; //根指针初始化,s为空树
 if (j >= i)
 {
  s = node *(malloc(sizeof(node)));//建立根结点
  s->data = pre[i];
  k = u;
  while (ind[k] != pre[i]) //在中序序列中查找根结点
   k++;
  l = i + k - u; //l为左字树中最右下结点在前序序列中的位置
  if (k == u) //构造左子树
   s->left = NULL;
  else
   bintree(i+1,l,u,k-1,s->left);
  if (k == v) //构造右子树
   s->right = NULL;
  else
   bintree(l+1,j,k+1,v,s->right);
 }
}
2003-7/*====================================================================================*/
/*函数名称:2003_7.c                                  */
/*程序目的:求由100个整数构成的序列L的最大和子序列                   */
/*Writen by Apechn ,Soft Lab of JLU                          */
/*====================================================================================*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const int N = 100;
void main()
{
  int A[N],stime;
  long ltime;
  int a = 0,b = 0,i,j,k,num = 0,max = -100;
  ltime = time(NULL);
  stime = (unsigned)ltime/2;
  srand(stime);
  for (i = 0;i<N;i++)
    A[i] = rand() % 100 - 50;
  printf("\nThe subserial is :\n");
  for (i = 0;i<N;i++)         //主要部分
    for (j = N-1;j>=i;j--)
    {                //i和j为子序列的边界
      num = 0;
      for (k = i;k<=j;k++)
        num += A[k];      //求出子序列的和
      if (num > max)        //如果当前序列的和大于记录,那么记下边界
      {
        max = num;
        a = i;
        b = j;
      }
    }
  for (k = a;k<=b;k++)
    printf("%3d",A[k]);
}
2003-8/*====================================================================================*/
/*函数名称:2003_8.c                                  */
/*程序目的:编程根据经过合理变换得到的序列B中的数据,依次输出序列A中的数值       */
/*Writen by Apechn ,Soft Lab of JLU                          */
/*====================================================================================*/
#include <stdio.h>
const int N = 10;
void main()
{
  int A[N],b[N] = {0,1,0,3,2,3,2,4,0,4};
  int temp[N] = {1,2,3,4,5,6,7,8,9,10};   //临时数组,在确定A时使用
  int i,j,k;
  for (i = N - 1;i>=0;i--)          //对数组B从后向前扫描
  {
    k = B[i];
    j = 0;
    while (k != 0)             //从临时数组temp中找到k=B[i]个没有确定下来的数
    {
      if (temp [j] != N + 1)
        k--;
      j++;
    }
    while (temp[j] == N + 1)       //找到下一个还没有被确定下来的数
      j++;               //就应该放到A[i]处
    A[i] = temp[j];
    temp[j] = N + 1;
  }
  for (i = 0;i<N;i++)
    printf("%d ",A[i]);
}

 

 

考研信息网在线版权与免责声明

1、 凡本站注明“稿件来源:考研信息网(sanwww.com)”的所有文字、图片和音视频稿件,版权均属本网所有,任何媒体、

网站或个人未经本网协议授权不得转载、转贴或以其他方式复制发表。已经本站协议授权的媒体、网站,在下载使用时

必须注明"稿件来源:sanwww.com",违者本站将依法追究责任。

2、本站注明稿件来源为其他媒体的文/图等稿件均为转载稿,本站转载出于非商业性的教育和科研之目的,并不意味着

赞同其观点或证实其内容的真实性。如转载稿涉及版权等问题,请作者在两周内速来电或来函联系。

3、考研试题、各种考试试题以及考试信息转载于各大bbs论坛,就其真实性本站无法证实,并不意味着赞同其观点。

如转载稿涉及版权等问题,请作者在两周内速来电或来函联系。

文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
           最新热点        最新推荐        相关文章
    吉林大学2004年硕士研究生入学考试
    吉林大学2004年硕士研究生入学考试
    吉林大学2004年硕士研究生入学考试
    吉林大学2003年硕士研究生入学考试
    吉林大学2002年硕士研究生入学考试
    吉林大学2002年硕士研究生入学考试
    吉林大学2002年硕士研究生入学考试
    吉林大学2002年硕士研究生入学考试
    吉林大学2001年硕士研究生入学考试
    吉林大学2001年硕士研究生入学考试
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)