2010計(jì)算機(jī)等考二級(jí)C:50套上機(jī)程序填空題(5)

字號(hào):

2010計(jì)算機(jī)等考二級(jí)C:50套上機(jī)程序填空題(5)

    9、給定程序中,函數(shù)fun的功能是:判斷形參s所指字符串是否是"回文"(Palindrome),若是,函數(shù)返回值為1;不是,函數(shù)返回值為0。"回文"是正讀和反讀都一樣的字符串(不區(qū)分大小寫字母)。21
    例如,LEVEL和Level是"回文",而LEVLEV不是"回文"。
    請(qǐng)?jiān)诔绦虻南聞澗€處填入正確的內(nèi)容并把下劃線刪除, 使程序得出正確的結(jié)果。
    注意:源程序存放在考生文件夾下的BLANK1.C中。
    不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    #include
    #include
    #include
    int fun(char *s)
    { char *lp,*rp;
    /**********found**********/
    lp= __1__ ;
    rp=s+strlen(s)-1;
    while((toupper(*lp)==toupper(*rp)) && (lp
    /**********found**********/
    lp++; rp __2__ ; }
    /**********found**********/
    if(lp
    else return 1;
    }
    main()
    { char s[81];
    printf("Enter a string: "); scanf("%s",s);
    if(fun(s)) printf("\n\"%s\" is a Palindrome.\n\n",s);
    else printf("\n\"%s\" isn't a Palindrome.\n\n",s);
    }
    10、給定程序中,函數(shù)fun的功能是:把形參s所指字符串中最右邊的n個(gè)字符復(fù)制到形參t所指字符數(shù)組中,形成一個(gè)新串。若s所指字符串的長(zhǎng)度小于n,則將整個(gè)字符串復(fù)制到形參t所指字符數(shù)組中。
    例如,形參s所指的字符串為:abcdefgh,n的值為5,程序執(zhí)行后t所指字符數(shù)組中的字符串應(yīng)為:defgh。
    請(qǐng)?jiān)诔绦虻南聞澗€處填入正確的內(nèi)容并把下劃線刪除, 使程序得出正確的結(jié)果。
    注意:源程序存放在考生文件夾下的BLANK1.C中。
    不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    #include
    #include
    #define N 80
    void fun(char *s, int n, char *t)
    { int len,i,j=0;
    len=strlen(s);
    /**********found**********/
    if(n>=len) strcpy(__1__);
    else {
    /**********found**********/
    for(i=len-n; i<=len-1; i++) t[j++]= __2__ ;
    /**********found**********/
    t[j]= __3__ ;
    }
    }
    main()
    { char s[N],t[N]; int n;
    printf("Enter a string: ");gets(s);
    printf( "Enter n:"); scanf("%d",&n);
    fun(s,n,t);
    printf("The string t : "); puts(t);
    }