栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C期末题库4

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C期末题库4

1

void  TestFunc(); 
#include 
double fun(int n)
{
  
  
   


  
}

main()
{  int n=-1;
  while(n<0)
  { printf("Please input(n>0): ");   
  scanf("%d",&n); 
  }
  printf("nThe result is: %fn",fun(n));
  TestFunc();
}

void TestFunc()
{
  FILE *IN,*OUT;
   int i;
   double s;
   IN=fopen("in.dat","r");
  if(IN==NULL)
  {
    printf("Read FILE Error");
  }
  OUT=fopen("out.dat","w");
  if(OUT==NULL)
  {
    printf("Write FILE Error");
  }
  fscanf(IN,"%d",&i);
  s=fun(i);
  fprintf(OUT,"%lf",s);
  fclose(IN);
  fclose(OUT);
}

答案

int i; 
   double s,t;
   s=0;
  for(i=1;i<=n;i++)
  { t=2.0*i;
     s=s+(2.0*i-1)*(2.0*i+1)/t;
  }
   return s; 

2


#include 
void  bky(); 

void copy(char str1[],char str2[])
{
  
  
  
  
  
  
  
  
}

main()
{
  void copy();
  char c1[40],c2[40];
  gets(c1);
  copy(c1,c2);
  puts(c2);
  bky();
}


void bky()
{
  FILE *IN,*OUT;
  char i[100];
  char o[100];
  IN=fopen("in.dat","r");
  if(IN==NULL)
  {
    printf("Read FILE Error");
  }
  OUT=fopen("out.dat","w");
  if(OUT==NULL)
  {
    printf("Write FILE Error");
  }
  fscanf(IN,"%s",i);
  copy(i,o);
  fprintf(OUT,"%sn",o);
  fclose(IN);
  fclose(OUT);
}

答案

int i;
    for(i=0;str1[i]!='';i++)
       str2[i]=str1[i];
    str2[i]='';


3


#include
#define N 10

void max(int a[],int n)
main()
{
        int a[N],i;
        for(i=0;ia[i])   
      {max=a[i]; p=i;}
   t=a[0];a[0]=a[p];a[p]=t;
   printf("nmax=%dn",max);
}

答案

【学生答案】
【参考答案】
void max(int a[],int n);
【改错2】	错误
【学生答案】
max(int a[],int N);
【参考答案】
max(a,N);
【改错3】	正确
【学生答案】
max=a[0];
【参考答案】
max=a[0];

==============================
【改错4】	正确
【学生答案】
if(max 

4


#include 
main( )
{
  
  long a,b,c,d,e,x,
  scanf("%ld",&x);
  a=x/10000;
  
  b=x/10000/1000;
  c=x%1000/100;
  d=x%100/10;
  e=x%10;
  
  if (a==0)
    printf("它是5位数: %ld %ld %ld %ld %ldn",e,d,c,b,a);
  else if (b!=0)
    printf("它是4位数: %ld %ld %ld %ldn",e,d,c,b);
  else if (c!=0) 
    printf("它是3位数: %ld %ld %ldn",e,d,c);
  else if (d!=0)
    printf("它是2位数: %ld %ldn",e,d);
  else if (e!=0) 
    printf("它是1位数: %ldn",e);
}

答案

【改错1】	正确
【学生答案】
long a,b,c,d,e,x;
【参考答案】
long a,b,c,d,e,x;

==============================
【改错2】	正确
【学生答案】
b=x%10000/1000;
【参考答案】
b=x%10000/1000;

==============================
【改错3】	正确
【学生答案】
if (a!=0)
【参考答案】
if (a!=0)

==============================

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/630378.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号