C期末题库4

C期末题库4,第1张

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)

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5636259.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存