上一题下一题
跳转到
 
 
  世界如此多姿,发展如此迅速,窥一斑未必还能知全豹。但正如万花筒一样,每一个管窥都色彩斑斓。  
 
 
  知识通道 | 学习首页 | 教师首页 | PK首页 | 知识创造首页 | 企业首页 | 登录
 
本文对应知识领域
c语言 上机题库(74-81)
作者:未知 申领版权
2010年12月12日 共有 1550 次访问 【添加到收藏夹】 【我要附加题目
受欢迎度:

    74. 给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),将所指数组中大于平均值的数据移至数组的前部,小于等于平均值的数据移至x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。
    例如,有10个正数:46  30  32  40  6  17  45  15  48  26,平均值为:30.500000
    移动后的输出为:46  32  40  45  48  30  6  17  15  26
    #include  <stdlib.h>
    #include  <stdio.h>
    #define   N   10
    double fun(double  *x)
    { int  i, j;    double  s, av, y[N];
    s=0;
    for(i=0; i<N; i )  s=s x[i];
    /*******************************found******************************/
    av=__1__;  s/N
    for(i=j=0; i<N; i )
    if( x[i]>av ){
    /*******************************found******************************/
    y[__2__]=x[i]; x[i]=-1;}   j
    for(i=0; i<N; i )
    /*******************************found******************************/
    if( x[i]!= __3__)  y[j ]=x[i];   -1
    for(i=0; i<N; i )x[i] = y[i];
    return  av;
    }
    main( )
    { int  i;     double  x[N];
    for(i=0; i<N; i ){ x[i]=rand()%50; printf("%4.0f ",x[i]);}
    printf("\n");
    printf("\nThe average is: %f\n",fun(x));
    printf("\nThe result :\n",fun(x));
    for(i=0; i<N; i )  printf("%5.0f ",x[i]);
    printf("\n");  }
    
    75. 给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),作为函数值返回;并将大于平均值的数放在形参y所指数组中,在主函数中输出。例如,有10个正数:46  30  32  40  6  17  45  15  48  26,平均值为:30.500000
    #include  <stdlib.h>
    #define   N   10
    double fun(double  x[],double  *y)
    { int  i,j;    double  av;
    /*******************************found******************************/
    av=__1__;  0
    /*******************************found******************************/
    for(i=0; i<N; i )  av = av   __2__;  x[i]/N 
    for(i=j=0; i<N; i )
    /*******************************found******************************/
    if(x[i]>av)  y[__3__]= x[i];   j
    y[j]=-1;
    return  av;
    }
    main( )
    {  int  i;    double  x[N],y[N];
    for(i=0; i<N; i ){ x[i]=rand()%50; printf("%4.0f ",x[i]);}
    printf("\n");
    printf("\nThe average is: %f\n",fun(x,y));
    for(i=0; y[i]>=0; i )  printf("%5.1f ",y[i]);
    printf("\n"); }
    
    76. 给定程序中,函数fun的功能是:将形参s所指字符串中的所有字母字符顺序前移,其他字符顺序后移,处理后新字符串的首地址作为函数值返回。
    例如,s所指字符串为:asd123fgh543df,处理后新字符串为:asdfghdf12543。
    #include  <stdio.h>
    #include  <stdlib.h>
    #include  <string.h>
    char *fun(char  *s)
    { int  i, j, k, n;    char  *p, *t;
    n=strlen(s) 1;
    t=(char*)malloc(n*sizeof(char));
    p=(char*)malloc(n*sizeof(char));
    j=0; k=0;
    for(i=0; i<n; i )
    {  if(((s[i]>='a')&&(s[i]<='z'))||((s[i]>='A')&&(s[i]<='Z'))) {
    /*******************************found******************************/
    t[j]=__1__; j ;}   s[i]
    else   {  p[k]=s[i]; k ; }
    }
    /*******************************found******************************/
    for(i=0; i<__2__; i )  t[j i]=p[i];  k
    /*******************************found******************************/
    t[j k]= __3__;   ‘\0’
    return  t; }
    main( )
    { char  s[80];
    printf("Please input: ");  scanf("%s",s);
    printf("\nThe result is: %s\n",fun(s));  }
    
    77. 给定程序中,函数fun的功能是:找出100~999之间(含100和999)所有整数中各位上数字之和为x(x为一正整数)的整数,然后输出;符合条件的整数个数作为函数值返回。
    例如,当x值为5时,1~999之间各位上数字之和为5的整数有:104、113、122、131、140、203、212、221、230、302、311、320、401、410、500。共有15个。当x值为27时,各位数字之和为27的整数是:999。只有1个。
    #include  <stdio.h>
    fun(int  x)
    { int  n, s1, s2, s3, t;
    n=0; t=100;
    /*******************************found******************************/
    while(t<=__1__)     999
    /*******************************found******************************/
    { s1=t%10;  s2=(__2__)%10;  s3=t/100;   t/10
    /*******************************found******************************/
    if(s1 s2 s3==__3__)    x
    {  printf("%d ",t);
    n ; }
    t ;
    }
    return  n;
    }
    main( )
    { int x=-1;
    while(x<0)
    { printf("Please input(x>0): ");  scanf("%d",&x);  }
    printf("\nThe result is: %d\n",fun(x));  }
    
    78. 给定程序中,函数fun的功能是将参数给定的字符串、整数、浮点数写到文本文件中,再用字符串方式从此文本文件中逐个读入,并调用库函数atoi和atof将字符串转换成相应的整数、浮点数,然后将其显示在屏幕上。
    #include  <stdio.h>
    #include  <stdlib.h>
    void fun(char  *s, int  a, double  f)
    {
    /*******************************found******************************/
    __1__ fp;     FILE*
    char  str[100], str1[100], str2[100];
    int  a1;     double  f1;
    fp = fopen("file1.txt", "w");
    fprintf(fp, "%s  %d  %f\n", s, a, f);
    /*******************************found******************************/
    __2__ ;    floes(fp)
    fp = fopen("file1.txt", "r");
    /*******************************found******************************/
    fscanf(__3__,"%s%s%s", str, str1, str2);    fp
    fclose(fp);
    a1 = atoi(str1);  f1 = atof(str2);
    printf("\nThe result :\n\n%s %d %f\n", str, a1, f1);
    }
    main( )
    { char  a[10]="Hello!";   int  b=12345;
    double  c= 98.76;  fun(a,b,c);  }
    
    79. 程序通过定义学生结构体变量,存储了学生的学号、姓名和3门课的成绩。所有学生数据均以二进制方式输出到文件中。函数fun的功能是重写形参filename所指文件中最后一个学生的数据,即用新的学生数据覆盖该学生原来的数据,其它学生的数据不变。
    #include  <stdio.h>
    #define    N    5
    typedef struct  student
    {  long  sno;
    char  name[10];
    float  score[3];
    } STU;
    void fun(char  *filename, STU  n)
    { FILE  *fp;
    /*******************************found******************************/
    fp = fopen(__1__, "rb ");      filename
    /*******************************found******************************/
    fseek(fp, -1L*sizeof(STU), __2__);   SEEK_END
    /*******************************found******************************/
    fwrite(__3__, sizeof(STU), 1, fp);   &n
    fclose(fp);  }
    main()
    { STU  t[N]={ {10001,"MaChao", 91, 92, 77},{10002,"CaoKai", 75, 60, 88},
    {10003,"LiSi", 85, 70, 78},  {10004,"FangFang", 90, 82, 87},
    {10005,"ZhangSan", 95, 80, 88}};
    STU  n={10006,"ZhaoSi", 55, 70, 68}, ss[N];
    int  i,j;      FILE  *fp;
    fp = fopen("student.dat", "wb");  fwrite(t, sizeof(STU), N, fp);  fclose(fp);
    fp = fopen("student.dat", "rb");  fread(ss, sizeof(STU), N, fp);  fclose(fp);
    printf("\nThe original data :\n\n");
    for (j=0; j<N; j )
    {  printf("\nNo: %ld  Name: %-8s Scores:  ",ss[j].sno, ss[j].name);
    for (i=0; i<3; i )  printf("%6.2f ", ss[j].score[i]);
    printf("\n");  }
    fun("student.dat", n);
    printf("\nThe data after modifing :\n\n");
    fp = fopen("student.dat", "rb");
    fread(ss, sizeof(STU), N, fp);
    fclose(fp);
    for (j=0; j<N; j )
    {  printf("\nNo: %ld  Name: %-8s Scores:  ",ss[j].sno, ss[j].name);
    for (i=0; i<3; i )  printf("%6.2f ", ss[j].score[i]);
    printf("\n");  }
    }
    
    80. 给定程序中,函数fun的功能是计算下式
    S=- -…
    直到≤,并把计算结果作为函数值返回。
    例如:若形参e的值为1e-6,函数的返回值为-0.205601
    #include  <stdio.h>
    double fun(double  e)
    {  int  i, k;    double  s, t, x;
    s=0;  k=1;  i=2;
    /*******************************found******************************/
    x=__1__/4;   3.0
    /*******************************found******************************/
    while(x __2__ e)  >
    {  s=s k*x;  k=k* (-1);  t=2*i;
    /*******************************found******************************/
    x=__3__*(2*i 1)/(t*t);   (2*i-1)
    i ;  }
    return  s;
    }
    main( )
    {  double  e=1e-6;
    printf("\nThe result is: %f\n",fun(e));  }
    
    81. 给定程序中,函数fun的功能是:在形参ss所指字符串数组中查找与形参t所指字符串相同的串,找到后返回该串在字符串数组中的位置(下标值),未找到则返回-1。ss所指字符串数组中共有N个内容不同的字符串,且串长小于M。
    #include  <stdio.h>
    #include  <string.h>
    #define   N   5
    #define   M   8
    int fun(char  (*ss)[M],char  *t)
    {  int  i;
    /*******************************found******************************/
    for(i=0; i< __1__ ; i )    N
    /*******************************found******************************/
    if(strcmp(ss[i],t)==0 ) return  __2__ ;  i
    return -1;
    }
    main( )
    { char  ch[N][M]={"if","while","switch","int","for"},t[M];
    int  n,i;
    printf("\nThe original string\n\n");
    for(i=0;i<N;i )puts(ch[i]);  printf("\n");
    printf("\nEnter a string for search:  ");  gets(t);
    n=fun(ch,t);
    /*******************************found******************************/
    if(n==-1)  printf("\nDon't found!\n");
    else   printf("\nThe position is  %d .\n",n);
    }
    

 

相关新闻

肢体语言塑造你自己
杂谈语言(之六)——文字改革(下):一失足成千古恨的文字改革
杂谈语言(之五)——文字改革(上):半吊子的改革最糟糕!
杂谈语言(之四)——续谈广东话的口头语(2)
杂谈语言(之四)——续谈广东话的口头语(1)
杂谈语言(之三)——那些深受古汉语影响的语言(方言)
杂谈语言(之二)——语言学习的边际成本递减效应
没有战争,美国就活不下去
制度优越还是债务优越?(之一)
波兰(二)

您可能对这些感兴趣  

第7讲 综合分析BIM在运用与推广中的障碍问题
考核学生质量的困难
日本福岛核电站事故初步分析
论科技异化与科技人化
中国科技计划项目管理现状与对策
财政科技资金的审计重点和内容
软科学研究机构在政府决策中的功效、困境及对策研究
打造超级DOS系统(下)
DOS命令基础应用(6)
打造超级DOS系统(上)

题目筛选器
日期:
类型:
状态:
得分: <=
分类:
作者:
职业:
关键字:
搜索

 
 
 
  焦点事件
 
  知识体系
 
  职业列表
 
 
  最热文章
 
 
  最多引用文章
 
 
  最新文章
 
 
 
 
网站介绍 | 广告服务 | 招聘信息 | 保护隐私权 | 免责条款 | 法律顾问 | 意见反馈
版权所有 不得转载
沪ICP备 10203777 号 联系电话:021-54428255
  帮助提示    
《我的太学》是一种全新的应用,您在操作中遇到疑问或者问题,请拨打电话13564659895,15921448526。
《我的太学》