zoukankan      html  css  js  c++  java
  • 2014年考研885编程大题

    第一题:

    #include <stdio.h>
    double fun(int n,double x){
        if(n==0) return 1;
        else if(n==1) return 2*x;
        else return 2*x*fun(n-1,x)-2*(n-1)*fun(n-2,x);
    }
    int main(){
        double x;
        int n;
        scanf("%d%lf",&n,&x);
        printf("%lf
    ",fun(n,x));
        return 0;
    }

    第二题:

    #include <stdio.h>
    #include <math.h>
    #define eps 1e-6
    int main(){
        double x1,x2=2;
        int n=1;
        do{
            n++;
            x1=x2;
            x2=pow(1+1.0/n,n);
        }while(fabs(x1-x2)>eps);
        printf("e的值为%lf,n=%d
    ",x2,n);
        return 0;
    }

    第三题:

    #include <stdio.h>
    #include <math.h>
    struct student{
        int no;//学号
        char name[20];//姓名
        double score[3];//三科成绩
        double sum;//总成绩
        int rank;//排名 
    };
    int main(){
        int i,j;double sum;
        FILE *fp=fopen("student.dat","w+");
        printf("请输入需要输入的学生个数:
    ");
        int n;
        scanf("%d",&n);
        struct student stu[n];
        printf("输入每个学生的信息:
    ");
        for(i=0;i<n;i++){
            printf("输入第%d个学生的信息
    ",i+1);
            scanf("%d%s",&stu[i].no,stu[i].name);
            sum=0.0;
            for(j=0;j<3;j++){
                scanf("%lf",&stu[i].score[j]);
                sum+=stu[i].score[j];
            }
            stu[i].sum=sum;
        }
        struct student temp,k;
        //进行排名
        int index;
        for(i=0;i<n;i++){
            k=stu[i];index=i;
            for(j=i+1;j<n;j++){
                if(k.sum<stu[j].sum){
                    k=stu[j];
                    index=j;
                }
            }
            temp=stu[i];
            stu[i]=k;
            stu[index]=temp;
        }
        //进行名次排序,总分相同的名次相同
        int rank=1;
        for(i=0;i<n;i++){
            if(i==0){
                stu[i].rank=rank;rank++;
            }else{
                if(stu[i].sum==stu[i-1].sum){
                    stu[i].rank=stu[i-1].rank;
                    rank++;
                }else{
                    stu[i].rank=rank;
                    rank++;
                }
            }
        }
        //进行输出
        printf("全体学生信息输出:(按总分排序)
    ");
        printf("学号	姓名	数学	语文	英语	总分	名次
    ");
        for(i=0;i<n;i++){
            printf("%d	%s	%lf	%lf	%lf	%lf	%d
    ",stu[i].no,stu[i].name,
            stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].sum,stu[i].rank);
            fprintf(fp,"%d	%s	%lf	%lf	%lf	%lf	%d
    ",stu[i].no,stu[i].name,
            stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].sum,stu[i].rank);
        }
        fclose(fp);
        return 0;
    } 

    测试数据:

    2001 liu 100 100 100
    2002 Li   90 90 90
    2003 wang 80 80 80
    2004 bao 70 70 70
    2005 yu 60 60 60
    2006 chen 50 50 50
    2007 luo 80 80 80
    2008 xu 90 90 90
    2009 jian 100 100 100
    2010 xiao 90 90 90 

      收录于《考研计算机885复习》

  • 相关阅读:
    C# WebApi 获取客户端ip地址
    C# 构造函数快捷键
    2 .SHELL 5~10节
    Spring项目集成apidoc生成api接口文档
    根据域名查找对应的ip及端口
    高质量SQL的30条建议
    1 .shell编程1~5
    CentOS7安装mysql8
    编译安Apache2.4.43报错checking for APR... no configure: error: APR not found. Please read the documentation.
    rm -rf * 的正确用法
  • 原文地址:https://www.cnblogs.com/byczyz/p/13795929.html
Copyright © 2011-2022 走看看