計(jì)算機(jī)二級(jí)考試C語(yǔ)言操作題題庫(kù)_第1頁(yè)
計(jì)算機(jī)二級(jí)考試C語(yǔ)言操作題題庫(kù)_第2頁(yè)
計(jì)算機(jī)二級(jí)考試C語(yǔ)言操作題題庫(kù)_第3頁(yè)
計(jì)算機(jī)二級(jí)考試C語(yǔ)言操作題題庫(kù)_第4頁(yè)
計(jì)算機(jī)二級(jí)考試C語(yǔ)言操作題題庫(kù)_第5頁(yè)
已閱讀5頁(yè),還剩13頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1 下列程序定義了n n 的二維數(shù)組 并在主函數(shù)中自動(dòng)賦值 請(qǐng)編寫(xiě)函數(shù)fun int a n 該函數(shù)的功能是 使數(shù)組左下半三角元素中的值全部置成 0 答案 i in nt t f fu un n i in nt t a a N N i in nt t I I j j f fo or r i i 0 0 i i N i N i f fo or r j j 0 0 j j I j I j a a i i j j 0 0 2 請(qǐng)編寫(xiě)函數(shù) fun 對(duì)長(zhǎng)度位 7 個(gè)字符的字符串 除首尾字符外 將其余 5 個(gè)字符按 ascii 碼降序排列 答案 voidvoid fun charfun char s int s int num num charchar t t intint I j I j for i 1 ifor i 1 i num 2 i num 2 i for j i 1 jfor j i 1 j num 1 j num 1 j 3 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 將 s 所指字符串中除了下標(biāo)為偶數(shù) 同時(shí) ascii 值也為偶 數(shù)的字符外 其余的全都刪除 串中剩余字符所形成的一個(gè)新串放在 t 所指的一個(gè)數(shù)組中 答案 voidvoid fun charfun char s char s char t t intint I j 0 n I j 0 n n strlen s n strlen s for i 0 I n i for i 0 I n i if i 2 0t j s i j j t j 0 t j 0 4 請(qǐng)編寫(xiě)函數(shù) fun 該函數(shù)的功能是 將 m 行 n 列的二維數(shù)組中的字符數(shù)據(jù) 按列的順序 依次放到一個(gè)字符串中 答案 voidvoid fun charfun char s n c s n c harhar b b intint i j k 0 i j k 0 for j 0 jfor j 0 j n j n j for i 0 ifor i 0 i m i m i b k s i j b k s i j k k b k 0 b k 0 5 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 將所有大于 1 小于整數(shù) m 的非素?cái)?shù)存入 xx 所指的數(shù)組中 非素?cái)?shù)的個(gè)數(shù)通過(guò) k 傳回 答案 void fun int m int k int xx int i j int n 0 for i 4 i m i for j 2 j i j if i j 0 break if j 0 else if a 10 else if a 20 else if a 30 else if a 40 else if a 50 else if a 60 else if a 70 else if a 80 else if a 90 else b 10 1 7 請(qǐng)編寫(xiě)函數(shù) fun 其功能時(shí) 將兩個(gè)兩位數(shù)的正整數(shù) a b 合并形成一個(gè)整數(shù)放在 c 中 合并的方式是 將 a 數(shù)的十位和個(gè)位數(shù)依次放在 c 數(shù)的十位和千位上 b 的十位和個(gè)位整 數(shù)依次放在 c 數(shù)的百位和個(gè)位上 答案 void fun int a int b long c c a 10 1000 b 10 100 a 10 10 b 10 8 請(qǐng)編寫(xiě)函數(shù) fun 其功能使 將兩個(gè)兩位正整數(shù) a b 合并形成一個(gè)整數(shù)放在 c 中 合并 的方式使 將 a 數(shù)的十位和個(gè)位數(shù)依次放在 c 數(shù)的百位和個(gè)位上 b 數(shù)的十位和個(gè)位數(shù)依 次放在 c 數(shù)的千位和十位上 答案 void fun int a int b long c c b 10 1000 a 10 100 b 10 10 a 10 9 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 將兩個(gè)兩位數(shù)的正整數(shù) a b 合并形成一個(gè)整數(shù)放在 c 中 合 并的方式是 將 a 數(shù)的十位和個(gè)位數(shù)依次放在 c 的十位和千位上 b 數(shù)的十位和個(gè)位數(shù)依 次放在 c 數(shù)的個(gè)位和百位上 答案 void fun int a int b long c c a 10 1000 b 10 100 a 10 10 b 10 10 m 個(gè)人的成績(jī)存放在score 數(shù)組中 請(qǐng)編寫(xiě)函數(shù)fun 它的功能是 將低于平均分的人 作為函數(shù)值返回 將低于平均分的分?jǐn)?shù)放在below 所指定的函數(shù)中 答案 i in nt t f fu un n i in nt t s sc co or re e i i n nt t m m i in nt t b be el lo ow w i in nt t i i k k 0 0 a av ve er r 0 0 f fo or r i i 0 0 i i m i m i a av ve er r s sc co or re e i i a av ve er r m m f fo or r i i 0 0 i i m i m i i if f s sc co or re e i i s max h s DoDo if q s max if q s max max q s max q s q q next q q next while q 0 while q 0 returnreturn max max 14 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 將 s 所指字符串中除了下標(biāo)為奇數(shù) 同時(shí) ascii 值也為 奇數(shù)的字符之外 其余的所有字符都刪除 串中剩余字符所形成的一個(gè)新串放在 t 所指的 一個(gè)數(shù)組中 答案 voidvoid fun charfun char s char s char t t intint I j 0 n I j 0 n n strlen s n strlen s for i 0 I n i for i 0 I n i if i 2 0t j s i j j t j 0 t j 0 15 下列程序定義了 n n 的二維數(shù)組 并在主函數(shù)中自動(dòng)賦值 請(qǐng)編寫(xiě)函數(shù) fun int a n int n 該函數(shù)的功能是 將數(shù)組右上半三角元素中的值乘以 m 答案 voidvoid fun intfun int a n inta n int m m intint i j i j for j 0 jfor j 0 j n j n j for i 0 ifor i 0 i j i j i a j a j m a j a j m 16 已知學(xué)生的記錄是由學(xué)號(hào)和學(xué)習(xí)成績(jī)構(gòu)成 n 名學(xué)生的數(shù)據(jù)已存入 a 機(jī)構(gòu)體數(shù)組中 請(qǐng) 編寫(xiě)函數(shù) fun 該函數(shù)的功能是 找出成績(jī)最高的學(xué)生記錄 通過(guò)形參返回主函數(shù) 規(guī)定只 有一個(gè)最高分 答案 void fun stu a stu s int i max max a 0 s for i 0 i n i if a s max max a s s a 17 編寫(xiě)一個(gè)函數(shù) fun 它的功能是 實(shí)現(xiàn)兩個(gè)字符串的連接 不使用庫(kù)函數(shù) strcat 即把 p2 所指的字符串連接到 p1 所指的字符串后 答案 void fun char p1 char p2 int i 0 n 0 char p p1 q p2 while p p n i n while p p1 q q i p1 0 18 編寫(xiě)一個(gè)函數(shù) 該函數(shù)可以統(tǒng)計(jì)一個(gè)長(zhǎng)度為 2 的字符串在另一個(gè)字符串中出現(xiàn)的次數(shù) 答案 intint fun charfun char str char str char substr substr intint n n charchar p r p r n 0 n 0 while str while str p str p str r substr r substr while r while r if r p if r p r r p p elseelse break break if r 0 if r 0 n n str str returnreturn n n 19 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 將 s 所指字符串中下標(biāo)位偶數(shù)同時(shí) ascii 值為奇數(shù)的字符 刪除 s 中剩余的字符形成的新串放在 t 所指的數(shù)組中 答案 void fun char s char t int i j 0 n strlen s for i 0 i n i if i 2 0 j t j 0 20 請(qǐng)編寫(xiě)函數(shù) fun 該函數(shù)的功能是 實(shí)現(xiàn) b a a 即把矩陣 a 加上 a 的轉(zhuǎn)置 存放在矩陣 b 中 計(jì)算結(jié)果在 main 函數(shù)中輸出 答案 void fun int a 3 3 int b 3 3 int i j at 3 3 for i 0 i 2 i for j 0 j 2 j at j a j for i 0 i 3 i for j 0 j 3 j b j a j at j 21 學(xué)生的記錄由學(xué)號(hào)和成績(jī)組稱(chēng)個(gè) n 名學(xué)生的數(shù)據(jù)已在主函數(shù)中放入結(jié)構(gòu)體數(shù)組 s 中 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是 把低于平均分的學(xué)生數(shù)據(jù)放在 b 所指的數(shù)組中 低于平均 分的學(xué)生人數(shù)通過(guò)形參 n 傳回 平均分通過(guò)函數(shù)值返回 答案 double fun strec a strec b int n double aver 0 0 int i j 0 n 0 for i 0 i n i aver a s aver n for i 0 i n i if a s aver b j a n j return aver 22 請(qǐng)編寫(xiě)一個(gè)函數(shù) fun 它的功能是 計(jì)算并輸出給定整數(shù) n 的所有因子 不包括 1 與自 身 之和 規(guī)定 n 的值不大于 1000 答案 int fun int n int s 0 i for i 2 i n 1 i if n i 0 s i return s 23 假定輸入的字符串中只包含字母和 號(hào) 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是 除了尾部的 號(hào) 之外 將字母串中其他 號(hào)全部刪除 形參 p 已指向字符串中最后的一個(gè)字母 不使用 c 的 字符串函數(shù) 答案 void fun char a char p int i 0 char p a while q l j return j 25 編寫(xiě)函數(shù)藏服那 它的功能是 求 n 以內(nèi) 不包括 n 同時(shí)能被 3 與 7 整除的所有自然數(shù) 之和的平方根 s 并作為函數(shù)值返回 答案 double fun int n double s 0 0 int i for i 1 i n i if i 3 0 s sqrt s return s 26 請(qǐng)編寫(xiě)函數(shù) fun 該函數(shù)的功能是 將 m 行 n 列的二維數(shù)組中的數(shù)據(jù) 按行的順序依 次放到一維數(shù)組中 一維數(shù)組中數(shù)據(jù)的個(gè)數(shù)存放在形參 n 所指的儲(chǔ)存單元中 答案 void fun int s 10 int b int n int mm int nn int i j for i 0 i mm i for j 0 j nn j b n s i j n n 1 27 請(qǐng)別寫(xiě)函數(shù) fun 該函數(shù)的功能是 將放在字符串?dāng)?shù)組中的 m 個(gè)字符串 每串的長(zhǎng)度不 超過(guò) n 按順序合并組成一個(gè)新的字符串 答案 void fun char a m n char b int i j k 0 for i 0 i m i for j 0 j n j if a i j b k a i j k else break b k 0 28 請(qǐng)編寫(xiě)函數(shù) fun 該函數(shù)的功能是 刪去一維數(shù)組中所有相同的數(shù) 使之只剩 一個(gè) 數(shù)組中的數(shù)已按由小到大的順序排列 函數(shù)返回刪除后數(shù)組中數(shù)據(jù)的個(gè)數(shù) 答案 int fun int a int n int i t j 0 p a t p 0 for i 0 i n i if t p else a j t t p j if i n a j t return j 29 程序定義了 n n 的二維數(shù)組 并在主函數(shù)中自動(dòng)賦值 請(qǐng)編寫(xiě)函數(shù) fun 該函數(shù)的功能 是 使數(shù)組左下半三角元素中的值乘以 n 答案 fun int a n int n int i j for i 0 i n i for j 0 j i j a j a j n 30 請(qǐng)編寫(xiě)函數(shù) fun 該函數(shù)的功能是 統(tǒng)一一含字符串中單詞的個(gè)數(shù) 作為函數(shù)值返回 一行字符串在主函數(shù)中輸入 規(guī)定所有單詞由小寫(xiě)字母組成 單詞之間由若干個(gè)空格格開(kāi) 一行的開(kāi)始沒(méi)有空格 答案 int fun char s int i n 0 for i 0 i strlen s i if s a return n 31 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 將 s 所指字符串中 ascii 值為奇數(shù)的字符刪除 串中剩余 字符形成一個(gè)新串放在 t 所指的數(shù)組中 答案 void fun char s char t int i j 0 n n strlen s for i 0 i n i if s 2 0 t j s j t j 0 32 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 將兩位數(shù)的正整數(shù) a b 合并成一個(gè)整數(shù)放在 c 中 合并 的方式是 將 a 數(shù)的十位和個(gè)位數(shù)依次放在 c 數(shù)的百位和個(gè)位上 b 數(shù)的十位和個(gè)位數(shù)依 次放在 c 數(shù)的十位和千位上 答案 void fun int a int b long c c b 10 1000 a 10 100 b 10 10 a 10 33 假定輸入的字符串中只包含字母和 號(hào) 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是 刪除字符串中 所有 號(hào) 在編寫(xiě)函數(shù)時(shí) 不得使用 c 語(yǔ)言提供的字符串函數(shù) 答案 void fun char a int i 0 char p a while p if p a p i p a 0 34 學(xué)生的記錄時(shí)由學(xué)號(hào)和成績(jī)組成 n 名學(xué)生的數(shù)據(jù)已在主函數(shù)中放入結(jié)構(gòu)體數(shù)組 s 中 請(qǐng)編寫(xiě)函數(shù) fun 它的功能時(shí) 函數(shù)返回指定學(xué)號(hào)的學(xué)生數(shù)據(jù) 指定的學(xué)號(hào)在主函數(shù)中輸 入 若沒(méi)找到指定學(xué)號(hào) 在結(jié)構(gòu)體變量中給學(xué)號(hào)置空串 給成績(jī)置 1 作為函數(shù)值返回 用于 字符串比較的函數(shù)時(shí) strcmp 答案 strec fun strec char b int i strec h for i 0 i n i if strcmp a num b 0 h a break else h num h s 1 return h 35 請(qǐng)編寫(xiě)函數(shù) fun 其功能時(shí) 計(jì)算并輸出下列多項(xiàng)式的值 sn 1 1 1 1 2 1 3 1 4 1 n 答案 sn 1 1 1 1 2 1 3 1 4 1 n double fun int n double t sn 1 0 int i j for i 1 i n i t 1 0 for j 1 j i j t j sn 1 0 t return sn 36 學(xué)生得記錄由學(xué)號(hào)和成績(jī)組稱(chēng)個(gè) n 名大學(xué)生得數(shù)據(jù)已在主函數(shù)中放入結(jié)構(gòu)體數(shù)組 s 中 請(qǐng)編寫(xiě)函數(shù) fun 它的功能時(shí) 按分?jǐn)?shù)的高低排列學(xué)生的記錄 高分在前 答案 voidvoid fun strecfun strec a a intint i j i j strecstrec t t for i 0 i n 1 i for i 0 i n 1 i for j i s n j for j i s n j if a s a j s if a s a j s t a t a a a j a a j a j t a j t 37 請(qǐng)編寫(xiě)一個(gè)函數(shù) void fun char ss 其功能時(shí) 將字符串 ss 中所有下標(biāo)為奇數(shù)位 置上的字母轉(zhuǎn)換為大寫(xiě) 若位置上不是字母 則不轉(zhuǎn)換 答案 voidvoid fun charfun char ss ss intint i n 0 i n 0 charchar p ss p ss while p while p n n p p forfor i 0 i i 0 i n i n i ifif ss a ss 0 38 請(qǐng)編寫(xiě)一個(gè)函數(shù) fun 它的功能時(shí) 求 fibonacci 數(shù)列中大于 t 的最小的一個(gè)數(shù) 結(jié)果由 函數(shù)返回 其中 fibonacci 數(shù)列 f n 的定義為 f 0 0 f 1 1 f n f n 1 f n 2 答案 f 0 0 f 1 1 f n f n 1 f n 2 int fun int t int a 1 b 1 c 0 i for i 4 i t i if c t c a b a b b c else break return c 39 編寫(xiě)函數(shù) fun 它的功能時(shí) 計(jì)算并輸出下列級(jí)數(shù)和 s 1 1 2 1 2 3 1 n n 1 答 案 double fun int n double s 0 0 int i for i 1 i n i s s 1 0 i i 1 return s 40 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 將 s 所指字符串中下標(biāo)為偶數(shù)的字符刪除 串中剩余字符 形成新串放在 t 所指數(shù)組中 答案 void fun char s char t int i j 0 n strlen s for i 0 i n i if i 2 0 t j s j t j 0 41 假定輸入的字符串中只包含字母和 號(hào) 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是 除了字符串前 導(dǎo)和尾部的 號(hào)之外 將串中其他 號(hào)全部刪除 形參 h 已指向字符串第一個(gè)字符 形參 p 已指向字符串中最后一個(gè)字母 在編寫(xiě)程序時(shí) 不得使用 c 語(yǔ)言提供的字符串函數(shù) 答案 void fun char a char h ch ar p int i 0 char q a while q h a q q i while q p if q a q i q while q a q i q a 0 42 學(xué)生的記錄由學(xué)號(hào)和成績(jī)組成 n 名學(xué)生的數(shù)據(jù)已在主函數(shù)中放入結(jié)構(gòu)體數(shù)組 s 中 請(qǐng) 編寫(xiě)函數(shù) fun 它的功能時(shí) 把分?jǐn)?shù)最低的學(xué)生數(shù)據(jù)放在 h 所指的數(shù)組中 注意 分?jǐn)?shù)最 低的學(xué)生可能不止一個(gè) 函數(shù)返回分?jǐn)?shù)最低的學(xué)生的人數(shù) 答案 int fun strec a strec b int i j 0 n 0 min min a 0 s for i 0 i n i if a s min min a s for i 0 i n i if a s min b j a j n return n 43 請(qǐng)編寫(xiě)函數(shù) fun 該函數(shù)的功能 將 m 行 n 列的二維數(shù)組中的數(shù)據(jù) 按列的順學(xué)依次 放到一維數(shù)組中 答案 void fun int s 10 int b int n int mm int nn int i j for j 0 j nn j for i 0 i mm i b n s i j n n 1 44 請(qǐng)編寫(xiě)函數(shù) fun 其功能時(shí) 計(jì)算并輸出當(dāng) x 0 97 時(shí)下列多項(xiàng)式的值 直到 sn s n 1 1e 6 return sum 45 請(qǐng)編寫(xiě)一個(gè)函數(shù) fun 其功能是 將兩個(gè)兩位數(shù)的正整數(shù) ab 合并形成一個(gè)整數(shù)放在 c 中 合并方式是 將 a 數(shù)的十位和個(gè)位數(shù)依次放在 c 數(shù)的個(gè)位和百位上 b 數(shù)的十位和個(gè) 位數(shù)依次放在 c 數(shù)的十位和千位上 答案 void fun int a int b long c c b 10 1000 a 10 100 b 10 10 a 10 46 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 將 s 所指字符串中 ascii 值為偶數(shù)的字符刪除 串 中剩余字符形成一個(gè)新串放在 t 所指的數(shù)組中 答案 void fun char s char t int i j 0 n strlen s for i 0 i n i if s 2 0 t j s j t j 0 47 請(qǐng)編寫(xiě)一個(gè)函數(shù)void fun int m int k int xx 該函數(shù)的功能是 將大于整數(shù) m 且緊靠 m 的 k 各素?cái)?shù)存入xx 所指的數(shù)組中 答案 v vo oi id d f fu un n i in nt t m m i in nt t k k i in nt t x xx x i in nt t g g 0 0 I I j j f fl la ag g 1 1 f fo or r i i m m 1 1 i i i i i if f k k 0 0 x xx x g g i i k k elseelse b br re ea ak k 48 已知學(xué)生的記錄由學(xué)號(hào)和學(xué)習(xí)成績(jī)構(gòu)成 n 名學(xué)生的數(shù)據(jù)已存入 a 結(jié)構(gòu)體數(shù)組中 請(qǐng)編 寫(xiě)函數(shù) fun 該函數(shù)的功能是 找出成績(jī)最低的學(xué)生記錄 通過(guò)形參返回主函數(shù) 規(guī)定只有 一個(gè)最低分 答案 void fun stu a stu s int i min min a 0 s for i 0 i n i if a s min min a s s a 49 n 名學(xué)生的成績(jī)已在主函數(shù)中放入一個(gè)帶頭節(jié)點(diǎn)的鏈表結(jié)構(gòu)中 h 指向鏈表的 頭節(jié)點(diǎn) 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是 求出平均分 由函數(shù)值返回 答案 double fun strec h double aver 0 0 while h null aver h s hy h next aver n return aver 50 請(qǐng)編寫(xiě)函數(shù) fun 計(jì)算并輸出給定 10 個(gè)數(shù)的方差 答案 double fun double x 10 int i j double s 0 0 s1 0 0 for i 0 i 10 i s1 x s1 10 for j 0 j 10 j s x j s1 x j s1 s 10 s pow s 0 5 return s 5 1 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 將兩個(gè)兩位數(shù)的正整數(shù) a b 合并形成一個(gè)整數(shù)放在 c 中 合并的方式是 將 a 數(shù)的十位和個(gè)位數(shù)依次放在 c 數(shù)的千位和十位上 b 數(shù)的十位和個(gè)位 數(shù)依次放在 c 數(shù)的個(gè)位和百位上 答案 void fun int a int b long c c a 10 1000 a 10 10 b 10 100 b 10 52 假定輸入的字符串中只包含字母和 號(hào) 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是 除了字符串前 導(dǎo)的 號(hào)之外 將串中其他 號(hào)全部刪除 在編寫(xiě)函數(shù)亞時(shí) 不得使用 c 語(yǔ)言提供的字符串 函數(shù) 答案 void fun char a int i 0 char p a while p i p while p if p a p i p a 0 53 學(xué)生的記錄是由學(xué)號(hào)和成績(jī)組成 n 名學(xué)生的數(shù)據(jù)已在主函數(shù)中放入結(jié)構(gòu)體數(shù)組 s 中 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是 把高于等于平均分的學(xué)生數(shù)據(jù)放在 b 所指的數(shù)組中 高于 等于平均分的學(xué)生人數(shù)通過(guò)形參 n 傳回 平均分通過(guò)函數(shù)值返回 答案 double fun strec a strec b int n double aver 0 0 int i j 0 for i 0 i n i aver a s aver n for i 0 i n i if a s aver b j a j n j return aver 54 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 計(jì)算并輸出下列多項(xiàng)式值 sn 1 1 2 1 3 1 4 1 2n 1 1 2n 答案 sn 1 1 2 1 3 1 4 1 2n 1 1 2n double fun int n int i double sn 0 0 for i 1 i n i sn 1 0 2 i 1 1 0 2 i return sn 55 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是 求出 1 到 100 之內(nèi)能被 7 或者 11 整除 但不能同時(shí)北 7 和 11 整除的所有證書(shū) 并將他們放在 a 所指的數(shù)組中 通過(guò) n 返回這些數(shù)的個(gè)數(shù) 答案 V Vo oi id d f fu un n i in nt t a a i in nt t n n i in nt t i i j j 0 0 f fo or r i i 2 2 i i 1 10 00 00 0 i i i if f i i 7 7 0 0 i i 1 11 1 0 0 n j n j 56 請(qǐng)編寫(xiě)函數(shù) void fun int x int pp int n 它的功能是 求出能整除x 且不是偶 數(shù)的各整數(shù) 并按從小到大的順序放在 pp 所指的數(shù)組中 這些除數(shù)的個(gè)數(shù)通過(guò)形參 n 返回 答案 v vo oi id d f fu un n i in nt t x x i in nt t p pp p i in nt t n n i in nt t i i 1 1 j j 0 0 k k 0 0 t t p pp p f fo or r i i 0 0 i i x i x i i if f i i 2 2 0 0 t t j j I I j j f fo or r i i 0 0 i i j i j i i if f x x t t i i 0 0 p pp p k k t t i i k k n k n k 57 請(qǐng)編寫(xiě)一個(gè)函數(shù)void fun char tt int pp 統(tǒng)計(jì)在 tt 字符中 a 到 z 26 各字母各自出現(xiàn)的次數(shù) 并依次放在pp 所指的數(shù)組中 答案 v vo oi id d f fu un n c ch ha ar r t tt t i in n t t p pp p i in nt t i i f fo or r i i 0 0 i i 26 i 26 i p pp p i i 0 0 w wh hi il le e t tt t s sw wi it tc ch h t tt t c ca as se e a a p pp p 0 0 b br re ea ak k c ca as se e b b p pp p 1 1 b b r re ea ak k c ca as se e c c p pp p 2 2 b b r re ea ak k casecase d d pp 3 bpp 3 br r e ea ak k c ca as se e e e p pp p 4 4 b br r e ea ak k c ca as se e f f p pp p 5 5 b b r re ea ak k c ca as se e g g p pp p 6 6 b b r re ea ak k c ca as se e h h p pp p 7 7 b b r re ea ak k c ca as se e i i p pp p 8 8 b b r re ea ak k c ca as se e j j p pp p 9 9 b b r re ea ak k c ca as se e k k p pp p 1 10 0 b br re ea ak k c ca as se e l l p pp p 1 11 1 b br re ea ak k c ca as se e m m p pp p 1 12 2 b br re ea ak k c ca as se e n n p pp p 1 12 2 b br re eak ak c ca as se e o o p pp p 1 14 4 b br re ea ak k c ca as se e p p p pp p 1 15 5 b br re ea ak k c ca as se e q q p pp p 1 16 6 b br re ea ak k c ca as se e r r p pp p 1 17 7 b br re ea ak k c ca as se e s s p pp p 1 18 8 b br re ea ak k c ca as se e t t p pp p 1 19 9 b br re ea ak k c ca as se e u u p pp p 2 20 0 b br re ea ak k c ca as se e v v p pp p 2 21 1 b br re ea ak k c ca as se e w w p pp p 2 22 2 b br re ea ak k casecase x x pp 23 pp 23 b b r re ea ak k c ca as se e y y p pp p 2 24 4 b br re ea ak k c ca as se e z z p pp p 2 25 5 b br re ea ak k tt tt 58 58 請(qǐng)編寫(xiě)一個(gè)函數(shù)int fun int s int t int k 用來(lái)求除數(shù)組的最大元素在數(shù) 組中的下標(biāo)并存放在 k 所指的儲(chǔ)存單元中 答案 v vo oi id d f fu un n i in nt t s s i in nt t t t i in nt t k k i in nt t I I m ma ax x m ma ax x s s 0 0 f fo or r i i 0 0 i i m ma ax x m ma ax x s s i i k I k I 59 編寫(xiě)函數(shù) fun 功能是 根據(jù)以下攻勢(shì)計(jì)算s 計(jì)算結(jié)果作為函數(shù)值返回 N 通過(guò)形參傳 入 S 1 1 1 2 1 1 2 3 1 1 2 3 4 n 答案 f fl lo oa at t f fu un n i in nt t n n i in nt t i i f fl lo oa at t s s 1 1 0 0 t t 1 1 0 0 f fo or r i i 2 2 i i n i n i t t t t i i s s s s 1 1 t t r re et tu ur rn n s s 60 編寫(xiě)一個(gè)函數(shù) fun 它的功能是 根據(jù)以下公式求p 的值 結(jié)果由函數(shù)值帶回 M 與 n 為兩個(gè)正整數(shù) 且要求m n p m n m n 答案 f fl lo oa at t f fu un n i in nt t m m i in nt t n n f fl lo oa at t p p t t 1 1 0 0 i in nt t I I f fo or r i i 1 1 i i m i m i t t t t I I p t p t f fo or r t t 1 1 0 0 i i 1 1 i i n n i i t t t t I I p p p p t t f fo or r t t 1 1 0 0 i i 1 1 i i m m n n i i t t t t I I p p p p t t r re et tu ur rn n p p 61 編寫(xiě)函數(shù) fun 它的功能是 利用以下的簡(jiǎn)單迭代方法求方程cos x x 0 的一 個(gè)實(shí)根 迭代步驟如下 1 取 x1 初值為 0 0 2 x0 x1 把 x1 的值賦各 x0 3 x1 cos x0 求出一個(gè)新的 x1 4 若 x0 x1 的絕對(duì)值小于0 則執(zhí)行步驟 5 否則執(zhí)行 步驟 2 5 所求 x1 就是方程 cos x x 0 的一個(gè)實(shí)根 作為函數(shù)值返回 程序?qū)⑤敵?root 0 答案 f fl lo oa at t f fu un n f fl lo oa at t x x1 1 0 0 0 0 x x0 0 dodo x x0 0 x x1 1 x x1 1 c co os s x x0 0 w wh hi il le e f fa ab bs s x x0 0 x x1 1 1 1e e 6 6 r re et tu ur rn n x x1 1 62 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是計(jì)算下列級(jí)數(shù)和 和值由函數(shù)值返回 S 1 x x 2 2 x 3 3 x n n 答案 double fun double x int n double s 1 0 p 1 0 int I j t for i 1 i n i t 1 for j 1 j i j t t j p p x s s p t return s 63 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 計(jì)算并輸出 s 1 1 2 0 5 1 2 0 5 3 0 5 1 2 0 5 3 0 5 n 0 5 答案 double fun int n int I double 1 0 p 1 0 for i 2 i n i p pow I 0 5 s p 64 規(guī)定輸入字符串中只包含字母和 號(hào) 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是 將函數(shù)字符串中 的前導(dǎo) 號(hào)全部刪除 中間和尾部的 號(hào)不刪除 答案 void fun char a int i 0 char p a while p while p a i p i p a i 0 65 號(hào)不得多于 n 個(gè) 若多于 n 個(gè) 則刪除多于的 號(hào) 若少于或等于 n 個(gè) 則什么也不 做 字符串中間和尾部的 號(hào)不刪除 答案 void fun char a int n int i 0 k 0 char t a while t k t t a if k n t a k n while t a i t i t a i 0 66 請(qǐng)編寫(xiě)函數(shù) fun 其功能使 計(jì)算并輸出給定數(shù)組 長(zhǎng)度為 9 中每相鄰兩個(gè)元素之平均 值的平方根之和 答案 double fun double x 9 double sum 0 0 int I j 1 for i 0 i 9 i if j 8 sum sqrt x i x i 1 2 0 j return sum 67 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 計(jì)算并輸出下列多項(xiàng)式值 s 1 1 1 2 1 1 2 3 1 1 2 3 50 答案 double fun int n int I j double sum 0 0 t for i 1 i n i t 0 0 for j 1 j I j t j sum 1 0 t return sum 68 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是 計(jì)算并輸出 n 包括 n 以內(nèi)能被 5 或 9 整除的所有自然數(shù) 的倒數(shù)之和 答案 double fun int n int I double sum 0 0 for i 1 i n i if i 5 0 i 9 0 sum 1 0 I return sum 69 請(qǐng)編寫(xiě)函數(shù) fun 其功能是 計(jì)算并輸出 3 到 n 之間所有素?cái)?shù)的平方根之和 答案 double fun int n int m k I double s 0 0 for m 3 m n m k sqrt m for i 2 i k i if m i 0 break if i k 1 s sqrt m return s 70 請(qǐng)編寫(xiě)函數(shù) fun 該函數(shù)的功能是 判斷字符串是否為回文 若是則函數(shù)返回 1 主函 數(shù)中輸出 yes 否則返回 0 主函數(shù)中輸出 no 回文是指順讀和倒讀都是一樣的字符串 答案 intint fun charfun char str str intint I n 0 I n 0 fg 1 fg 1 charchar p str p str whilewhile p p n n p p for i 0 ifor i 0 i n 2 i n 2 i ifif str i str n 1 i str i str n 1 i ElseElse fg 0 fg 0 break break returnreturn fg fg 71 學(xué)生的記錄由學(xué)號(hào)和成績(jī)組成 n 名學(xué)生的數(shù)據(jù)已在主函數(shù)中放入結(jié)構(gòu)體數(shù)組 s 中 請(qǐng)編寫(xiě)函數(shù) fun 它的功能使 把分?jǐn)?shù)最高的學(xué)生數(shù)據(jù)放在 h 所指的數(shù)組中 注意 分?jǐn)?shù) 最高的學(xué)生可能不止一個(gè) 函數(shù)返回分?jǐn)?shù)最高的學(xué)生的人數(shù) 答案 intint funfun STREC STREC a a STRESTRE C C b b intint I j 0 n 0 I j 0 n 0 max max max a 0 s max a 0 s for i 0 ifor i 0 i N i N i if a i s max if a i s max max a i max a i s s for i 0 ifor i 0 i N i N i if a i s max if a i s max b j a i b j a i j j n n returnreturn n n 72 請(qǐng)編寫(xiě)一個(gè)函數(shù) fun 它的功能是 將一個(gè)字符串轉(zhuǎn)換為一個(gè)整數(shù) 不得調(diào)用 c 語(yǔ)言提 供的將字符串轉(zhuǎn)換為整數(shù)的函數(shù) 答案 longlong funfun char char p p longlong s 0 t s 0 t intint i 0 j n strlen p k si 0 j n strlen p k s 1 1 if p 0 if p 0 i i for j I j n 1 j for j I j n 1 j t p j 0 t p j 0 s1 10 s1 10 for k j k n 1 k t s1 for k j k m if n m p s p s elseelse p t p t returnreturn p p 74 請(qǐng)編寫(xiě)一個(gè)函數(shù) fun 它的功能是 根據(jù)以下公式求 x 的值 要求滿足精度 0 0005 即 某項(xiàng)小于 0 0005 時(shí)停止迭代 x 2 1 1 3 1 2 3 5 1 2 3 3 5 7 1 2 3 4 3 5 7 9 1 2 3 n 3 5 7 2n 1 程序運(yùn)行后 如果輸入精度 0 0005 則程序輸出為 3 14 答案 doubledouble fun doublefun double eps eps doubledouble s s floatfloat n t pi n t pi t 1 pi 0 n 1 0 s 1 0 t 1 pi 0 n 1 0 s 1 0 while fabs s eps while fabs s eps pi s pi s t n 2 n 1 s t t n 2 n 1 s t n n pi pi 2 pi pi 2 returnreturn pi pi 75 請(qǐng)編寫(xiě)一個(gè)函數(shù) fun 它的功能是 求除 1 到 m 之內(nèi) 含 m 能北 7 或 11 整除的所有整數(shù) 放在數(shù)組 a 中 通過(guò) n 返回這些數(shù)的個(gè)數(shù) 答案 voidvoid fun intfun int m m intint a a intint n n intint I j 0 I j 0 n 0 n 0 for i 1 ifor i 1 i m i m i ifif i 7 0 i 7 0 i 11i 11 0 0 a j I a j I j j n j n j 76 請(qǐng)編寫(xiě)一個(gè)函數(shù) fun 它的功能是 找出一維整型數(shù)組元素中最大的值和它所在的下 標(biāo) 最大的值和它所在的下標(biāo)通過(guò)形參傳回 數(shù)組元素中的值已在主函數(shù)中賦予 主函數(shù) 中 x 是數(shù)組名 n 是 x 中的數(shù)據(jù)個(gè)數(shù) max 存放最大值 index 存放最大值所在元素的下標(biāo) 答案 voidvoid funfun int int a inta int n n intint max max inin t t d d intint I I max a 0 max a 0 d 0 d 0 for i 0 Ifor i 0 I n i n i if a i max if a i max max a i max a i d I d I 77 請(qǐng)編寫(xiě)一個(gè)函數(shù) fun 它的功能是 將 ss 所指字符串中所有下標(biāo)為奇數(shù)位置上的字母 轉(zhuǎn)換為大寫(xiě) 若該位置上不是字母 則不轉(zhuǎn)換 答案 voidvoid fun charfun char ss ss intint I n I n n strlen ss n strlen ss for i 1 i n i 2 for i 1 i a ss i ss i 32 78 請(qǐng)編寫(xiě)一個(gè)函數(shù) fun 它的功能是 求除一個(gè) 2 m 整型二維數(shù)組中最大元素的值 并 將此值返回調(diào)用函數(shù) 答案 intint fun intfun int a M a M intint I j max I j max max a 0 0 max a 0 0 for i 0 i 2 i for i 0 i 2 i for j 0 j M j for j 0 jmax if a i j max max a i j max a i j returnreturn max max 79 假定輸入的字符串中只包含字母和 號(hào) 請(qǐng)編寫(xiě)函數(shù) fun 它的功能是 使字符串中尾 部的 號(hào)不得多于 n 個(gè) 若多于 n 個(gè) 則刪除多于的 號(hào) 若少于或等于 n 個(gè) 則什么也不 做 字符串中間和前面的 號(hào)不刪除 答案 voidvoid fun charfun char a int a int n n intint i 0 k 0 i 0 k 0 charchar p p t t p t a p t a whilewhile t t t t t t while t while t k k t t t t if k n if k n whilewhile pa i p i i p p a i 0 a i 0 80 請(qǐng)編寫(xiě)一個(gè)函數(shù) 用來(lái)刪除字符串中的所有空格 答案 voidvoid fun charfun char str str intint i 0 i 0 charchar p str p str whilewhile p p if p if p str i p str i p i i p p str i 0 str i 0 81 假定輸入的字符串中只包含字母

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論