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

    30.请编写一个函数fun,它的功能是:求出—个2×M整型二维数组中最大元素的值,并将此值返回调用函数。
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #define M 4
    #include <stdio.h>
    fun (int   a[][M]  )
    {
    int i,j,max= a[0][0] ;
    for(i=0;i<2;i )
    for(j=0;j<M;j )
    if(max < a[i][j]) 
    max=a[i][j];
    return max;
    }
    
    main()
    {
    FILE *wf;
    int arr[2][M]={5,8,3,45,76,-4,12,82};
    printf("max=%d\n",fun(arr));
    wf=fopen("out.dat","w");
    fprintf (wf,"%d",fun(arr));
    fclose(wf);
    }
    
    31.请编写函数fun,其功能是:将s所指字符串中除了下标为偶数、同时ASCII值也为偶数的字符外,其余的全都删除;串中剩余字符所形成的一个新串放在t所指的数组中。
    例如,若s所指字符串中的内容为ABCDEFGl23456,其中字符A的ASCII码值为奇数,因此应当删除;其中字符B的ASCII码值为偶数,但在数组中的下标为奇数,因此也应当删除;而字符2的ASCII码值为偶数,所在数组中的下标也为偶数,因此不应当删除,其他依此类推。最后t所指的数组中的内容应是246。
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #include <conio.h>
    #include <stdio.h>
    #include<string.h>
    void fun(char*s, char t[])
    {
    int i,j=0;
    for(i=0;s[i]!= '\0' ;i )
    if(i%2==0  &&  s[i]%2==0)
    t[j ]=s[i];
    t[j]='\0';
    }
    main()
    {
    FILE *wf;
    char s[100] ,t[100];
    printf("\nPlease enter string S: ");
    scanf("%s",s);
    fun(s,t);
    printf("\nThe result is: %s\n",t);
    wf=fopen("out.dat","w");
    fun("ABCDEFG123456",t);
    fprintf(wf,"%s",t);
    fclose(wf);
    }
    
    32.请编写函数fun,其功能是:将s所指字符串中除了下标为奇数、同时ASCII值也为奇数的字符之外,其余的所有字符都删除,串中剩余字符所形成的一个新串放在t所指的数组中。
    例如,若s所指字符串中的内容为ABCDEFG12345,其中字符A的ASCII码值虽为奇数,但所在元素的下标为偶数,因此必需删除;而字符1的ASCII码值为奇数,所在数组中的下标也为奇数,因此不应当删除,其他依此类推。最后t所指的数组中的内容应是135。
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #include <conio.h>
    #include <stdio.h>
    #include <string.h>
    void fun (char *s, char t[ ])
    { int i, j=0, n;
    n=strlen(s);
    for( i=0; i<n; i )
    if(i%2!=0&&s[i]%2!=0)
    { t[j]=s[i];
    j ;}
    t[j]= '\0' ;
    }
    
    main()
    { char s[100], t[100];
    printf("\nplease enter string S:");
    scanf("%s",s);
    fun(s,t);
    printf("\nthe result is :%s\n", t);
    }
    33.假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:使字符串中尾部的*号不得多于n个;若多于n个,则删除多余的*号;若少于或等于n个,则什么也不做,字符串中间和前面的*号不删除。        
    例如,字符串中的内容为****A*BC*DEF*C*******,若n的值为4,删除后,字符串中的内容则应当是****A*BC*DEF*G****,若n的值7,则字符串中的内容仍为****A*BC*DEF*C*******。n的值在主函数中输入。在编写函数时,不得使用C语言提供的字符串函数。
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #include <stdio.h>
    #include <conio.h>
    void  fun ( char *a , int n )
    {  int i=0, k=0;  char *p, *t;
    p=t=a;
    while ( *t) t ;
    t--;
    while (*t==’*’) {k ; t-- ;}
    t ;
    if (k>n)
    { while(*p&&p<t n)
    { a[i] = *p;
    i ;
    p ; }
    a[i] = '\0';}
    }
    main()
    {
    FILE *wf;
    char s[81],*t="****A*BC*DEF*G*******";
    printf("Enter a string :\n");
    gets(s);
    fun(s);
    printf("The string after deleted:\n");
    puts(s);
    wf=fopen("out.dat","w");
    fun(t);
    fprintf(wf,"%s",t);
    fclose(wf);
    }
    
    
    34.学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:把分数最高的学生数据放在h所指的数组中,注意:分数最高的学生可能不只一个,函数返回分数最高的学生的人数。
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #include <stdio.h>
    #define    N    16
    typedef    struct 
    { char num[10];
    int  s ;
    }STRUC;
    int  fun (STRUC *a, STRUC *b)
    {
    int i,j=0,max=a[0].s;
    for(i=0;i<N;i )
    if(max<a[i].s) max=a[i].s;
    for(i=0;i<N;i )
    if(max==a[i].s) b[j ]=a[i];
    return j;
    }
    main ()
    {
    STRUC  s[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},
    {"GA001",91},{"GA007",72},{"GA008",64},{"GA006",87},
    {"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},
    {"GA011",66},{"GA017",64},{"GA018",64},{"GA016",72}};
    STRUC h[N];
    int i, n;
    FILE *out;
    n=fun(s,h);
    printf("The %d highest score :\n",n);
    for (i=0; i<n; i )
    printf("%s %4d\n ",h[i].num,h[i].s);
    printf("\n");
    out=fopen("out45.dat", "w");
    fprintf(out, "%d\n",n);
    for(i=0; i<n; i )
    fprintf(out, "%4d\n ",h[i].s);
    fclose(out);
    }
    
    35.请编写一个函数,用来删除字符串中的所有空格。
    例如,输入asd af aa z67,则输出为asdafaaz67。
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #include <stdio.h>
    #include <ctype.h>
    #include <conio.h>
    int fun(char *str)
    {char *p=str;
    for(; *str; str )
    if(*str!=' ') *p =*str;
    *p='\0';
    }
    main()
    {
    char str[81];
    int n;
    clrscr() 
    printf("Input a string:") 
    gets(str);
    puts(str);
    fun(str);
    printf("*** str: %s\n",str);
    NONO();
    }
    NONO()
    {
    /* 请在此函数内打开文件,输入调试数据,调用 fun 函数,输出数据,关闭文件。 */
    char str[81];
    int n = 0;
    FILE *rf, *wf 
    rf = fopen("b0803.in", "r") 
    wf = fopen("b0803.out", "w") 
    while(n < 10) {
    fgets(str, 80, rf);
    fun(str);
    fprintf(wf, "%s", str) 
    n  
    }
    fclose(rf) 
    fclose(wf) 
    }
    
    36.假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:将字符串中的前导*号全部移到字符串的尾部。
    例如,若字符串中的内容为*******A*BC*DEF*G****,移动后,字符串中的内容应当是A*BC*DEF*G**********。在编写函数时,不得使用C语言提供的字符串函数。
    ♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
    #include <stdio.h>
    #include <conio.h>
    void  fun ( char *a)
    {  int  i=0,n=0 ;  char *p ;
    p=a;
    while (*p=='*')
    {n  ; p ; }
    while (*p)
    { a[i]= *p ;
    i ;
    p  ; }
    while(n!=0)
    { a[i]= '*' ;
    i  ;
    n-- ; }
    a[i]= '\0' ;
    }
    main()
    {
    FILE *wf;
    char s[81],*t="****A*BC*DEF*G*******";
    printf("Enter a string :\n");
    gets(s);
    fun(s);
    printf("The string after deleted:\n");
    puts(s);
    wf=fopen("out.dat","w");
    fun(t);
    fprintf(wf,"%s",t);
    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。
《我的太学》