专业课真题复习(2020)

简介: 专业课真题复习(2020)

1.题目描述:

#include<stdio.h>
#include<stdlib.h>
float fact(int n)
{
  if(n==1)
  {
    return 1;
  }
  return n*fact(n-1);
}
int main(void)
{
  float sum=1.0;
  int i;
  for(i=1;1;i++)
  {
    printf("%f\n",1.0/fact(i));
    if((1.0/fact(i))<(1e-6))
    {
      break;
    }
    sum+=(1/fact(i));
  }
  printf("%f",sum);
  return 0;
}

2.题目描述:

编写程序,求1-100之间所有素数(又称质数)并输出。

#include<stdio.h>
int isprime(int n)
{
  int i;
  for(i=2;i<=n/2;i++)
  {
    if(n%i==0)
    {
      return 0;
    }
  }
  return 1;
}
int main(void)
{
  int i;
  for(i=2;i<100;i++)
  {
    if(isprime(i))
    {
      printf("%d\n",i);
    }
  }
  return 0;
}

3.题目描述:

编写程序,有10名学生,每名学生的数据包括:学号、姓名、三门课的成绩。要求:从键盘输入10名学生的数据,最后求出每门课的平均成绩,以及每个学生的平均成绩,并输出相应的结果。

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student{
  int no;
  char name[100];
  float english;
  float chinese;
  float math;
};
int main(void)
{
  struct student student[10];
  int i=0;
  float eaver=0;
  float caver=0;
  float maver=0;
  float paver=0;
  float stuaverage;
  printf("请输入10个学生的信息:");
  for(i=0;i<10;i++)
  {
    scanf("%d%s%f%f%f",&student[i].no,&student[i].name,&student[i].english,&student[i].chinese,&student[i].math);
  }
  for(i=0;i<3;i++)
  {
    eaver+=student[i].english;
    caver+=student[i].chinese;
    maver+=student[i].math;
  }
  printf("英语的平均成绩为:%f\n",eaver/10.0);
  printf("语文的平均成绩为:%f\n",caver/10.0);
  printf("数学的平均成绩为:%f\n",maver/10.0);
    for(i=0;i<10;i++)
    {
      stuaverage=(student[i].chinese+student[i].english+student[i].math)/3.0;
      printf("第%d个的平均成绩为%f",i,stuaverage);
      stuaverage=0;
  }
  return 0;
}

4.题目描述:

编写程序,功能为从键盘读入一组数据(10个整数),将其中的奇数和偶数分别保存在磁盘文件"odd.c"和"even.c"中,并输出两个文件中的内容。

#include<string.h>
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
  int i;
  int arr[10];
  FILE *fa,*fe;
    char str[100];
  if((fa=fopen("odd.c","w"))==NULL)
  {
    printf("can not open this file.");
    exit(0);
  }
  if((fe=fopen("even.c","w"))==NULL)
  {
    printf("can not open this file.");
    exit(0);
  }
  printf("请输入10个整数:\n");
  for(i=0;i<10;i++)
  {
    scanf("%d",&arr[i]);
    if(arr[i]%2==0)
    {
      fputc(arr[i]+'0',fa);//数字转成字符 
    }
    else{
      fputc(arr[i]+'0',fe);
    }
  }
    fclose(fa);
  fclose(fe);
    if((fa=fopen("odd.c","r"))==NULL)
  {
    printf("can not open this file.");
    exit(0);
  }
  if((fe=fopen("even.c","r"))==NULL)
  {
    printf("can not open this file.");
    exit(0);
  }
  fscanf(fa,"%s",str);
  puts(str);
  fscanf(fe,"%s",str);
  puts(str);
      fclose(fa);
  fclose(fe);
  return 0;
}
相关文章
|
4月前
|
测试技术
蓝桥杯刷题|01入门真题
蓝桥杯刷题|01入门真题
|
4月前
|
测试技术
蓝桥杯刷题|03入门真题
蓝桥杯刷题|03入门真题
|
4月前
|
测试技术
蓝桥杯刷题|02入门真题
蓝桥杯刷题|02入门真题
|
4月前
|
存储 安全 Java
复习总结01110
复习总结01110
|
4月前
|
存储 数据库
复习总结0111
复习总结0111
|
4月前
|
存储 网络协议 测试技术
复习软考之精读真题题解,猜猜这是哪年的真题吧
复习软考之精读真题题解,猜猜这是哪年的真题吧
27 0
专业课真题复习(2018)
专业课真题复习(2018)
84 0
专业课真题复习(2019)
专业课真题复习(2019)
92 0
专业课真题复习(2017)
专业课真题复习(2017)
76 0
专业课真题复习(2021)
专业课真题复习(2021)
108 0