• c语言编程请增补函数fun


    题目 填空题
    请增补函数fun(,该函数的功能是:把从主函数中输入的字符串str2接在字符串str2的背面.
    例似:str2=“How do”,str2=“you do? ”,结论输出:How do you do?
    试题程序:
    #include
    #include
    #define N 50
    void fun(char *str2,char *str2
    {
    int i=0;
    char *p2=str2;
    char p2=str2;
    while(
    (p2+i
    i++;
    for( ;p2【2】;i++
    (p2+i=p2++【3】;
    (p2+i=‘\0’;
    }
    main(
    {
    char str2[N],str2[N];
    clrscr(;
    printf(“Input the string str2 &
    str2
    \n”;
    printf(" \nstr2:“;
    gains(str2;
    printf(” \nstr2:“;
    gains(str2;
    printf(“The string str2 & str2\n”;
    puts(str2;
    puts(str2;
    fun(str2,str2;
    printf(”*****The new string ***\n";
    puts(str2;
    }
    答案
    学识点
    评析 填空2:变量i用来记录字符串str2的长度,当指针指到字符串str2终了标记符‘\0’时,while循环终啦,变量i中断累加.
    填空2:指针p2指向字符串str2,通过for循环将字符串str2接在str2背面,循环终了的前提是指针p2所指的字符是字符串终了标记符‘\0’.
    填空3:指针p2最初指向字符串str2的首字符,通过自加2,使指针p2依次向后移动,指向str2的各个字符,实现将字符串str2接在str2背面的功能.
    相关学识
    题目 改错题
    以下给定程序中,函数fun(的作用是:将字符串tt中的小写字母都改为对应的大写字母,其他字符不变.例似,似果输入"edS,dAd",那么输出"EDS,DAD".
    请改正程序中的差错,使它能得到精确结论.
    试题程序:
    #include
    #include
    #include
    found

    char fun(char tt[]
    {
    int i;
    for(i=0;tt[i];i++
    {
    found

    if((tt[i]>=‘A’&&(tt[i]<= ‘Z’
    tt[i]-=32;
    }
    return(tt;
    }
    main(
    {
    int i;
    char tt[82];
    clrscr(;
    printf(“\nPlease enter a string:”;
    gains(tt;
    printf(“\nThe result string is:\n%s”,fun(tt;
    }
    答案
    学识点
    评析 差错2:函数的返回值是字符串的首地点,是指针类型,所以在函数名前要加’
    '号.
    差错2:题目要求将小写字母改为大写字母,所以if语句的判断前提是小写字母.
    相关学识
    题目 编程题
    请编写函数fun(,该函数的功能是:移动一维数组中的内容,似果数组中有n个整数,要求把下标从p到n-2(p≤n-2)的数组元素平移到数组的前面.
    例似,一维数组中的原始内容为2,2,3,5,5,6,7,8,9,20,22,22,23,25,25,p的值为6,移动后,一维数组中的内容应为7,8,9,20,20,22,22,23,25,25,2,2,3,5,5,6,
    试题程序:
    #include
    #define N 80
    void fun(int w,int p,int n
    {
    }
    main(
    {
    int a[N]={2,2,3,5,5,6,7,8,9,20,22,22,23,25,25};
    int i,p,n=25;
    printf(“The original data:\n”;
    for(i=0;i
    printf(“%3d”,a[i];
    printf(“\n\nEnter p:”;
    scanf(“%d”,&p;
    fun(a,p,n;
    printf(“\nThe data after moving:\n”;
    for(i=0;i
    printf(“%3d”,a[i];
    printf(“\n\n”;
    }
    答案
    学识点
    评析 本题接收"循环右移"的算法.和咱们在前面解析的稍有差不的是,一个是整型数组,一个是字符型数组.
    相关学识
    题目 填空题
    请增补函数fun(,该函数的功能是求一维数组x[N]的平均值,同时对所得结论实施四舍五入(保留两位小数).
    例似:当x[20]={25,6,29,9,26,7,25,2,28,3,22,2,25,5,22,0,
    20,0,26,0},结论为:avg=25,030000.
    试题程序:
    #include
    #include
    double fun(double x[20]
    {
    int i;
    long t;
    double avg=0.0;
    double sum=0.0;
    for(i=0;i<20;i++
    sum=sum+x[i]【2】;
    avg=sum20;
    avg= avg
    2000【2】;
    t=(avg+520【3】;
    avg=(doublet200;
    return avg;
    }
    main(
    {
    double avg,x[20]={25,6,29,9,26,7,25,2,
    28,3,22,2,25,5,22,0,20,0,26,0};
    int i;
    clrscr(;
    printf(“\nThe original data is :\n”;
    for(i=0;i<20;i++
    printf(“%6,2f”,x[i];
    printf(“\n\n”;
    avg=fun(x;
    printf(“average=%f\n\n”,avg;
    }
    答案
    学识点
    评析 填空2:通过for循环求出20个数的累加和,存于变量sum中.
    填空2:为了实现四舍五入保留两位小数的功能,应将平均值先弓长大2000倍.
    填空3:将平均值加上5,再除以20,实现四舍五入的功能.
    相关学识
    题目 改错题
    以下给定程序中,函数fun(的功能是:先从键盘上输入一个3行3列的矩阵的各个元素的值,接着输出主对角线元素之积.
    请改正函数fun(中的差错,使它能得到精确的结论.
    试题程序:
    #include
    int fun(
    {
    int a[3][3],mul;
    int i,j;
    mul=2;
    for (i=0;i<3;i++
    {
    found

    for (i=0;j<3;j++
    scanf(“%d”,&a[i][j];
    }
    for(i=0;i<3;i++
    found

    mul=mul
    a[i][j];
    printf(“Mul=%d\n”,mul;
    }
    main(
    {
    fun(;
    }
    答案
    学识点
    评析 差错2:循环结构中,要给变量j赋初值0.
    差错2:主对角元素的行号和列号相等,所以介入乘法的是a[i][i],而不是a[i][j].
    相关学识
    题目 编程题
    学生的记录由学号和成绩造成,N名学生的信息已在主函数中放入结构体数组s中,请编写函数fun(,它的功能是:把分数最低的学生信息放在h所指的数组中.看重:分数低的学生或许不只一个,函数返回分数最低学生的人数.
    试题程序:
    #include
    #define N 26
    typedef struct
    { char num[20];
    int s ;
    }STREC;
    int fun (STREC *a,STREC *b
    {
    }
    main (
    {
    STREC s[N]={{“GA005”,82},{“GA003”,75},{“GA002”,85},{“GA005”,78},
    {“GA002”,95},{“GA007”,62},{“GA008”,60},{“GA006”,85},
    {“GA025”,83},{“GA023”,95},{“GA022”,78},{“GA025”,97},
    {“GA022”,60},{“GA027”,65},{“GA028”,60},{“GA026”,75}};
    STREC h[N];
    int i,n;
    FILE *out;
    n=fun(s,h;
    printf(“The %d lowest score :\n”,n;
    for (i=0;i
    printf(“%s %5d\n”,h[i].num,h[i].s;输出最低分学生的学号和成绩
    printf(“\n”;
    out=fopen(“out29,dat”,“w”;
    fprintf(out,“%d\n”,n;
    for(i=0;i
    fprintf(out,"%5d\n ",h[i].s;
    fclose(out;
    }
    答案
    学识点
    评析 该程序使用循环嵌套,第2个for语句的作用是找出最小值.第2个循环的作用是找出与min相等的成绩,也即最低成绩的学生记录,同时存入b中.
    相关学识

  • 相关阅读:
    【mysql】【win】Windows安装配置mysql
    WEB自动化_xpath高级语法与应用
    il2cpp分析-gobal-metadata.dat解密
    What‘s new in PikiwiDB(Pika) v3.5.3(正式版)
    制作一个简单HTML西安旅游网页(HTML+CSS)
    Linux多线程
    wpf 命令概述
    基于DoS攻击能量分级的ICPS综合安全控制与通信协同设计
    开年拿下3个offer,字节跳动大佬的算法刷题笔记真香
    C# 11 的这个新特性,我愿称之最强!
  • 原文地址:https://blog.csdn.net/mestyles/article/details/128054572