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

    55.请编写函数fun,该函数的功能是:将M行N列的二维数组中的数据,按行的顺序依次放到一维数组中,一维数组中数据的个数存放在形参n所指的存储单元中。
    例如,若二维数组中的数据为:33    33    33    33
    44    44    44    44
    55    55    55    55
    则一维数组中的内容应是:33  33  33  33  44  44  44  44  55  55  55  55
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #include <stdio.h>
    void fun (int (*s)[10], int *b, int *n, int mm, int nn)
    {
    int i,j,k=0;
    for(i=0;i<mm;i )
    for(j=0;j<nn;j )
    b[k ]= s[i][j] ;
    *n =k;
    }
    main()
    {
    FILE *wf;
    int w[10][10]={{33,33,33,33},{44,44,44,44},{55,55,55,55}}, i, j;
    int a[100]={0},n=0 ;
    printf("The matrix:\n");
    for (i=0; i<3; i )
    {for (j=0;j<4;j )  
    printf("%3d",w[i][j]);
    printf("\n");
    }
    fun(w,a, &n,3,4);
    printf("The A array:\n");
    for(i=0; i<n; i )  
    printf("%3d",a[i]); 
    printf("\n\n");
    wf=fopen("out.dat","w");
    for(i=0; i<n; i )  
    fprintf(wf,"%3d",a[i]); 
    fclose(wf);
    }
    
    56.假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:除了尾部的*号之外,将字符串中其他*号全部删除。形参p已指向字符串中最后的一个字母。在编写函数时,不得使用C语言提供的字符串函数。
    例如,若字符串中的内容为****A*BC*DEF*G*******,删除后,字符串中的则内容应当是ABCDEFG*******。
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #include<conio.h>
    #include<stdio.h>
    void fun(char *a,char *p)
    {
    char *t=a;
    for(;t<=p;t )
    if(*t!='*' ) 
    *(a )=*t;
    for(;*t!='\0' ;t )
    *(a )=*t;
    *a='\0';
    }
    main()
    { 
    FILE *wf;
    char h[81],*t,p[81]="****A*BC*DEF*G******";
    printf("Enter a string:\n "); 
    gets(h);
    t=h;
    while(*t)
    t ;
    t--;
    while(*t=='*') 
    t--;
    fun(h,t);
    printf("The string after deleted:\n"); 
    puts(h);
    wf=fopen("out.dat","w");
    t=p;
    while(*t)
    t ;
    t--;              
    while(*t=='*') 
    t--;   
    fun(p,t);
    fprintf(wf,"%s",p);
    fclose(wf); 
    }
    
    57.学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:把指定分数范围内的学生数据放在b所指的数组中,分数范围内的学生人数由函数值返回。
    例如,输入的分数是60和69,则应当把分数在60到69的学生数据进行输出,包含60分和69分的学生数据。主函数中将把60放在low中,把69放在high中。
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #include <stdio.h>
    #define  N  16
    typedef  struct
    { char num[10];
    int  s ;
    }STRUC;
    int  fun (STRUC *a, STRUC *b, int l, int h )
    {
    int i,j=0;
    for(i=0;i<N;i )
    if(a[i].s>=l  && a[i].s<=h)
    b[j ]=a[i];
    return j;
    }
    
    main ()
    {
    FILE *wf;
    STRUC  s[N]={{ "GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},
    {"GA001",96},{"GA007",72},{"GA008",64},{"GA006",87},
    {"GA015",85},{"GA013",94},{"GA012",64},{"GA014",91},
    {"GA011",90},{"GA017",64},{"GA018",64},{"GA016",72}};
    STRUC h[N],tt; 
    FILE *out;
    int i, j, n, low, heigh, t;
    printf("Enter 2 integer number low & heigh: ");
    scanf("%d%d",&low,&heigh);
    if(heigh<low ) 
    {t=heigh;heigh=low; low=t;}
    n=fun(s,h,low, heigh);
    printf("The student 's data between %d--%d:\n ",low, heigh);
    for(i=0;i<n;i )
    printf("%s %4d\n ",h[i].num, h[i].s);
    printf("\n ");
    out=fopen("out74.dat ", "w");
    fprintf(out, "%d\n ",n);
    n=fun(s,h,80,98);
    for(i=0;i<n-1;i )
    for(j=i 1;j<n;j )
    if(h[i].s>h[j].s) 
    {tt=h[i];h[i]=h[j];h[j]=tt;}
    for(i=0;i<n;i )
    fprintf(out, "%4d\n ",h[i].s);
    fprintf(out, "\n ");
    fclose(out);
    wf=fopen("out.dat","w");
    for(i=0;i<n;i )
    fprintf(wf, "%s %4d ",h[i].num, h[i].s);
    fclose(wf);
    }
    
    58.编写函数fun,它的功能是:求n以内(不包括n)同时能被3与7整除的所有自然数之和的平方根s,并作为函数值返回。
    例如,若n为1000时,函数值应为s=153.909064。
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #include <conio.h>
    #include <math.h>
    #include <stdio.h>
    double fun(int n)
    { int sum,i;sum=0;
    for(i=0;i<n;i )
    {if(i%3==0&&i%7==0)
    sum=sum i;}
    return (sqrt(sum));
    }
    main()
    {clrscr();
    printf("s=%f\n",fun(1000));
    }
    59.请编写函数fun,该函数的功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按顺序合并组成一个新的字符串。
    例如,若字符串数组中的M个字符串为:AAAA
    BBBBBBB
    CC
    则合并后的字符串的内容应是AAAABBBBBBBCC。
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #include <stdio.h>
    #include <conio.h>
    #define M 3
    #define N 20
    void fun(char a[M][N],char *b)
    {
    int i,j, k=0;
    for(i=0;i<M;i )
    for(j=0;a[i][j]!='\0';j )
    b[k ]=a[i][j];
    b[k]='\0';
    }
    main()
    { 
    FILE *wf;
    char w[M][N]={"AAAA", "BBBBBBB", "CC"},i;
    char a[100]={ " ##############################"};
    printf("The string:\n ");
    for(i=0;i<M;i ) 
    puts(w[i]);
    printf("\n ");
    fun(w,a);
    printf("The A string:\n ");
    printf("%s ",a);
    printf("\n\n ");
    wf=fopen("out.dat","w");
    fprintf(wf,"%s",a);
    fclose(wf);
    }
    

 

相关新闻

每一个程序员要遵守的一些优秀编程风格
《VB程序设计基础》选择题
设计模式之Iterator
设计模式之Visitor
设计模式之Interpreter(解释器)
设计模式之Mediator(中介者)
设计模式之Strategy(策略)
设计模式之State
设计模式之Command
设计模式之Chain of Responsibility(职责链)

您可能对这些感兴趣  

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

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

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