全國計(jì)算機(jī)等級(jí)二級(jí)C語言上機(jī)改錯(cuò)題題型

字號(hào):

第1題
    給定程序MODI1.C中函數(shù) fun 的功能是:把在字符串s中出現(xiàn)的每個(gè)字符,緊隨其后重復(fù)出現(xiàn)一次,形成一個(gè)新串放在t中,t中字符按原字符串中字符順序排列。
    
    例如:當(dāng)s中的字符串為:"ABAABBCCDDEE"。
    
     則t中的字符串應(yīng)為:"AABBCCDDEE"。
    
    請(qǐng)改正函數(shù)fun中的錯(cuò)誤,使它能得出正確的結(jié)果。注意:不要改動(dòng)main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    Modi1.c
    #include
    #include
    #include
    /************found************/
    
    void fun (char s,char t) /參考答案:void fun (char *s,char *t)/
    
    { int i, sl;
     sl = strlen(s);
     for (i=0; i { t[2*i] = s[i];
     t[2*i+1] = s[i];
     }
    
    /************found************/
    
     t[2*sl] = ’0’; /參考答案:t[2*sl] = ’\0’;/
    
    }
    main()
    
    { char s[100], t[100];
    
     clrscr();
    
     printf("\nPlease enter string s:"); scanf("%s", s);
    
     fun(s, t);
    
     printf("The result is: %s\n", t);
    
    } 第2題
    給定程序MODI1.C中函數(shù) fun 的功能是:把在字符串s中出現(xiàn)的每個(gè)字符, 緊隨其后重復(fù)出現(xiàn)一次,放在一個(gè)新串t中,t中字符按原字符串中逆排列。
    例如:當(dāng)s中的字符串為:"ABCDE"時(shí),
     則t中的字符串應(yīng)為:"EEDDCCBBAA"。
    請(qǐng)改正函數(shù)fun中的錯(cuò)誤,使它能得出正確的結(jié)果。注意:不要改動(dòng)main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    Modi1.c
    #include
    #include
    #include
    void fun (char *s, char *t)
    { int i, sl;
     sl = strlen(s);
    /************found************/
     for (i=1; i { t[2*i] = s[sl-i-1];
     t[2*i +1] = s[sl-i-1];
     }
    /************found************/
     t[2*sl] = ’0/’; /參考答案:t[2*sl] = ’\0’;/
    }
    
    main()
    { char s[100], t[100];
     clrscr();
     printf("\nPlease enter string s:"); scanf("%s", s);
     fun(s, t);
     printf("The result is: %s\n", t);
    }
    第3題
    給定程序MODI1.C中函數(shù) fun 的功能是:將在字符串s中下標(biāo)為偶數(shù)位置上的字符,緊隨其后重復(fù)出現(xiàn)一次,放在一個(gè)新串t中,t中字符按原字符串中字符的順序排列。(注意0為偶數(shù))
    例如:當(dāng)s中的字符串為:"ABCDE"時(shí),
     則t中的字符串應(yīng)為:"AACCEE"。
    請(qǐng)改正函數(shù)fun中的錯(cuò)誤,使它能得出正確的結(jié)果。注意:不要改動(dòng)main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    Modi1.c
    #include
    #include
    #include
    void fun (char *s, char *t)
    { int i, j, sl;
     sl = strlen(s);
    /************found************/
     for (i=0, j=0; i { t[2*j] = s[i];
     t[2*j +1] = s[i];
     j++;
     }
    /************found************/
     t[2*sl] = ’\0’; /參考答案:t[2*j]=’\0’;/
    }
    
    main()
    { char s[100], t[100];
     clrscr();
     printf("\nPlease enter string s:"); scanf("%s", s);
     fun(s, t);
     printf("The result is: %s\n", t);
    }第4題
    給定程序MODI1.C中函數(shù) fun 的功能是:將在字符串s中下標(biāo)為奇數(shù)位置上的字符,緊隨其后重復(fù)出現(xiàn)一次,放在一個(gè)新串t中,t中字符按原字符串中字符的順序排列。(注意0為偶數(shù))
    例如:當(dāng)s中的字符串為:"ABCDEF"時(shí),
     則t中的字符串應(yīng)為:"BBDDFF"。
    請(qǐng)改正函數(shù)fun中的錯(cuò)誤,使它能得出正確的結(jié)果。注意:不要改動(dòng)main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    Modi1.c
    #include
    #include
    #include
    
    void fun (char *s, char *t)
    { int i, j, sl;
     sl = strlen(s);
    /************found************/
     for (i=0, j=0; i { t[2*j] = s[i];
     t[2*j +1] = s[i];
    /************found************/
     j--; /參考答案:j++/
     }
     t[2*j] = ’\0’;
    }
    
    main()
    { char s[100], t[100];
     clrscr();
     printf("\nPlease enter string s:"); scanf("%s", s);
     fun(s, t);
     printf("The result is: %s\n", t);
    } 第5題
    
    給定程序MODI1.C中函數(shù) fun 的功能是:將在字符串s中下標(biāo)為偶數(shù)位置上的字符,緊隨其后重復(fù)出現(xiàn)一次,放在一個(gè)新串t中,t中字符按原字符串中字符出現(xiàn)的逆序排列。(注意0為偶數(shù))
    例如:當(dāng)s中的字符串為:"ABCDEF"時(shí),
       則t中的字符串應(yīng)為:"EECCAA"。
    請(qǐng)改正函數(shù)fun中的錯(cuò)誤,使它能得出正確的結(jié)果。注意:不要改動(dòng)main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    
    
    Modi1.c
    #include
    #include
    #include
    
    void fun (char *s, char *t)
    { int i, j, sl;
     sl = strlen(s);
     if(sl%2)sl--; else sl-=2;
    /************found************/
     for (i=sl, j=0; i>=0; i--) /參考答案:for (i=sl, j=0; i>=0; i-=2)/
     { t[2*j] = s[i];
     t[2*j +1] = s[i];
     j++;
     }
    /************found************/
     t[2*sl] = ’\0’; /參考答案:t[2*j] = ’\0’;/
    }
    
    main()
    { char s[100], t[100];
     clrscr();
     printf("\nPlease enter string s:"); scanf("%s", s);
     fun(s, t);
     printf("The result is: %s\n", t);
    } 第6題
    給定程序MODI1.C中函數(shù) fun 的功能是:將在字符串s中下標(biāo)為奇數(shù)位置上的字符,緊隨其后重復(fù)出現(xiàn)一次,放在一個(gè)新串t中,t中字符按原字符串中字符出現(xiàn)的逆序排列。(注意0為偶數(shù))
    例如:當(dāng)s中的字符串為:"ABCDEFG"時(shí),
     則t中的字符串應(yīng)為:"FFDDBB"。
    請(qǐng)改正函數(shù)fun中的錯(cuò)誤,使它能得出正確的結(jié)果。注意:不要改動(dòng)main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    Modi1.c
    #include
    #include
    #include
    
    void fun (char *s, char *t)
    { int i, j, sl;
     sl = strlen(s);
    /************found************/
     if(sl%2) Sl-=2; else Sl--; /參考答案:if(sl%2) sl-=2; else sl--;/
     for (i=sl, j=0; i>=0; i-=2)
     { t[2*j] = s[i];
     t[2*j +1] = s[i];
     j++;
     }
    /************found************/
     t[2*sl] = ’0’; /參考答案:t[2*j] = ’\0’;/
    }
    
    main()
    { char s[100], t[100];
     clrscr();
     printf("\nPlease enter string s:"); scanf("%s", s);
     fun(s, t);
     printf("The result is: %s\n", t);
    }
     第7題
    給定程序MODI1.C中函數(shù) fun 的功能是:把在字符串s中出現(xiàn)的每個(gè)字符,緊隨其后重復(fù)出現(xiàn)一次,形成一個(gè)新串放在t中,且在t中把原相鄰字符的位置進(jìn)行了交換。
    例如:當(dāng)s中的字符串為:"ABCDE"時(shí),
     則t中的字符串應(yīng)為:"BBAADDCCEE"。
    請(qǐng)改正函數(shù)fun中的錯(cuò)誤,使它能得出正確的結(jié)果。注意:不要改動(dòng)main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    Modi1.c
    #include
    #include
    #include
    
    void fun (char *s, char *t)
    {
    /************found************/
     int i, j; /參考答案:int i,j,sl;/
     sl = strlen(s);
     for (i=0, j=0; i { if (i+1 < sl)
     { t[2*j] = s[i+1]; t[2*j +1] = s[i+1];
     j++;
     }
     t[2*j] = s[i]; t[2*j +1] = s[i];
    /************found************/
     j--; /參考答案:j++;/
     }
     t[2*sl] = ’\0’;
    }
    
    main()
    { char s[100], t[100];
     clrscr();
     printf("\nPlease enter string s:"); scanf("%s", s);
     fun(s, t);
     printf("The result is: %s\n", t);
    }第8題
    給定程序MODI1.C中函數(shù) fun 的功能是:將在字符串s中出現(xiàn)、而未在字符串t中出現(xiàn)的字符形成一個(gè)新的字符串放在u中,u中字符按原字符串中字符順序排列,不去掉重復(fù)字符。
    例如:當(dāng)s = "AABCDE",t = "BDFG"字符。
    u中的字符串為"AACE"。
    請(qǐng)改正函數(shù)fun中的錯(cuò)誤,使它能得出正確的結(jié)果。注意:不要改動(dòng)main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    Modi1.c
    #include
    #include
    #include
    
    /************found************/
    void fun (char *s, char *t, char u) /參考答案:void fun (char *s, char *t, char *u)
    { int i, j, sl, tl;
     sl = strlen(s); tl = strlen(t);
     for (i=0; i { for (j=0; j if (s[i] == t[j]) break;
    /************found************/
     if (j>tl) /參考答案:if (j>=tl)
     *u++ = s[i];
     }
     *u = ’\0’;
    }
    
    main()
    { char s[100], t[100], u[100];
     clrscr();
     printf("\nPlease enter string s:"); scanf("%s", s);
     printf("\nPlease enter string t:"); scanf("%s", t);
     fun(s, t, u);
     printf("the result is: %s\n", u);
    } 第9題
    給定程序MODI1.C中函數(shù) fun 的功能是:將未在字符串s中出現(xiàn)而在字符串t中出現(xiàn)的字符形成一個(gè)新的字符串放在u中,u中字符按原字符串中字符順序排列,不去掉重復(fù)字符。
    例如:當(dāng)s = "ABCDE",t = "BDFGG"時(shí),
    u中的字符串為"FGG"。
    請(qǐng)改正函數(shù)fun中的錯(cuò)誤,使它能得出正確的結(jié)果。注意:不要改動(dòng)main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    Modi1.c
    #include
    #include
    #include
    
    void fun (char *s, char *t, char *u)
    { int i, j, sl, tl;
     sl = strlen(s); tl = strlen(t);
    /************found************/
     for (i=0; i/************found************/
     { for (j=0; j if (t[i] == s[j]) break;
     if (j>=sl) *u++ = t[i];
     }
    /************found************/
     u = ’\0’; /參考答案 *u = ’\0’;
    }
    
    main()
    { char s[100], t[100], u[100];
     clrscr();
     printf("\nPlease enter string s:"); scanf("%s", s);
     printf("\nPlease enter string t:"); scanf("%s", t);
     fun(s, t, u);
     printf("The result is: %s\n", u);
    } 第10題
    給定程序MODI1.C中函數(shù) fun 的功能是:將既在字符串s中出現(xiàn)又在字符串t中出現(xiàn)的字符構(gòu)成一個(gè)新的字符串放在u中,u中字符按原字符串中字符順序排列,不去掉重復(fù)字符。
    例如:當(dāng)s="ABBCDE",t="BDFG"時(shí),u中的字符串為:"BBD"。
    請(qǐng)改正函數(shù)fun中的錯(cuò)誤,使它能得出正確的結(jié)果。注意:不要改動(dòng)main函數(shù),不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
    Modi1.c
    #include
    #include
    #include
    
    void fun (char *s, char *t, char *u)
    { int i, j, sl, tl;
     sl = strlen(s); tl = strlen(t);
     for (i=0; i { for (j=0; j if (s[i] == t[j]) break;
    /************found************/
     if (j>=tl) /參考答案if (j *u++ = s[i];
     }
    /************found************/
     *u = ’0’; /參考答案*u = ’\0’;
    }
    
    main()
    { char s[100], t[100], u[100];
     clrscr();
     printf("\nPlease enter string s:"); scanf("%s", s);
     printf("\nPlease enter string t:"); scanf("%s", t);
     fun(s, t, u);
     printf("The result is: %s\n", u);
    }