C程序設(shè)計(jì) 譚浩強(qiáng) 期末考試習(xí)題_第1頁(yè)
C程序設(shè)計(jì) 譚浩強(qiáng) 期末考試習(xí)題_第2頁(yè)
C程序設(shè)計(jì) 譚浩強(qiáng) 期末考試習(xí)題_第3頁(yè)
C程序設(shè)計(jì) 譚浩強(qiáng) 期末考試習(xí)題_第4頁(yè)
C程序設(shè)計(jì) 譚浩強(qiáng) 期末考試習(xí)題_第5頁(yè)
已閱讀5頁(yè),還剩3頁(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、一、填空題1輸入一個(gè)不包含空格的字符串,將字符串反序輸出,如:“abc12”的輸出為“21cba”。#include <stdio.h> void f(char *p)char *p1, *p2;char c; p1=p2= ; while( *p2+) ; ; while ( ) c=*p1;*p1= ;*p2= ; p1+; p2-; void main() char s200; printf(“輸入一個(gè)字符串:”);scanf( );f(s); printf(“字符串反序:%sn”,s);2輸入1個(gè)長(zhǎng)整數(shù),求各位數(shù)字的平方和。 例如:輸入 123,輸出14。#include

2、<stdio.h>void main( ) int digit; long in,s; scanf("%ld", &in); ; ; while(in>0) ; s=s+digit*digit; ; printf("sum=%ldn", s);二、程序閱讀題1寫出下面程序運(yùn)行結(jié)果(5分)#include <stdio.h>#define MSIZE 8void main()char imMSIZEMSIZE+1=“*”,“#”,“#*#*#”,“#*#”,“*”,“#*”,“*”,“#”;int i,j;for(j=

3、 MSIZE -1;j>=0;j-)for(i=0;i<MSIZE;i+)printf(“%c”,imij);printf(“n”);2寫出下面程序運(yùn)行的輸出結(jié)果(5分)#include <stdio.h>void main() char *str1="", *str2=”5”; int x=0, i; for(i=0;str1i!='0'&& str2i!='0'i+) if(str1i=str2i) x+; printf("%dn",x); 3寫出下列程序的輸出結(jié)果 (4分)#i

4、nclude <stdio.h>main() int a=4,b=6; printf("a=%dn",a<<1); printf("b=%dn",b>>1);4. 寫出調(diào)用函數(shù)f(-123)的輸出結(jié)果是多少。(6分)void f(int n)if(n<0) printf(“-”);f(-n);else if(n<2) printf(“%d”,n);elsef(n/2);printf(“%d”,n%2);三、讀程序,找出其中存在的10個(gè)錯(cuò)誤并修改。#include <stdio.h>#define

5、 NUM 3struct problems char problem20; int answer; myprosNUM=”2+3=?”,5,”2*3-13=?”,-7,“(2*31*5)%3=?”,1;int main( void ) int i=0,a,score; printf(“test begin:n”)for(i=0,i<num;i+)printf(“problem %d:n”,i+1);printf(“%cn”, problemsi. problem);scanf(“%d”,a);if(a=problemsi.answer) score+;score=10×scor

6、e;printf(“your score: %dn”,score); return 0; /* indicates successful termination */ /* end main */ 錯(cuò)誤的語(yǔ)句: 修改為:1、2、3、4、5、6、7、8、9、10、四、編程。1、首先按要求生成兩個(gè)有序鏈表p和q如下圖所示:43 NULL1112p 97 NULL1315q 然后將這兩個(gè)鏈表合并生成一個(gè)新的鏈表head,使得head仍然從大到小有序,并且不允許有重復(fù)的元素。最后將新的鏈表輸出。(本題25分)比如,p、q鏈表中節(jié)點(diǎn)data的值若分別為:p: 12,11,10,9,8,7,6,5,4,3

7、q: 15,13,11,9,7則生成的head鏈表中節(jié)點(diǎn)data的值為:15,13,12,11,10,9,8,7,6,5,4,3#include <stdio.h>#include <malloc.h>struct nodeint data; struct node *next;void main() int a=12,11,10,9,8,7,6,5,4,3; int b=15,13,11,9,7; struct node *p,*q,*head;/* 以下程序?qū)崿F(xiàn)生成鏈表p和q,使得p鏈表中節(jié)點(diǎn)data的值依次為a數(shù)組, q鏈表中節(jié)點(diǎn)data的值依次為b數(shù)組*/ /*

8、按題意要求合并生成新的鏈表head*/ /*輸出鏈表head*/ 2把一英文文章中的字母全部轉(zhuǎn)換成密文字母輸出到另一個(gè)文件中,文中其他字符以及換行不變。字母轉(zhuǎn)換規(guī)則為:A->E,B->F,V->Z,W->A,Z->D, a->e,b->f,v->z,w->a,z->d,即變成其后面第四個(gè)字母。文件名用命令行參數(shù)給出。假設(shè)源程序名encrypt.c,命令行寫法如下: encrypt script.txt cipher.txt其中script.txt為原始的英文文章,cipher.txt為完成加密后的新文件。(本題15分)二一、填空題1輸

9、入10個(gè)點(diǎn)的坐標(biāo)(設(shè)坐標(biāo)為整數(shù)值), 輸出距原點(diǎn)最遠(yuǎn)的點(diǎn)(設(shè)唯一)的坐標(biāo)及該點(diǎn)距原點(diǎn)的距離.#include <math.h>void main() struct int x, y; float length; point10; int k, sub=0; for(k = 0; k <10; k+) scanf("%d%d", &pointk.x, &pointk.y); pointk.length = for(k=1; k<10; k+) if( ) printf("(%d,%d) %fn", pointsub.

10、x, pointsub.y, pointsub.length);2以下程序統(tǒng)計(jì)從終端輸入的字符中大寫字母的個(gè)數(shù),num0中統(tǒng)計(jì)字母A的個(gè)數(shù),num1中統(tǒng)計(jì)字母B的個(gè)數(shù),其它依次類推.用#號(hào)結(jié)束輸入,請(qǐng)?zhí)羁?#include <stdio.h>#include <ctype.h>main() int num26=0,i; char c; while(_)!='#') if(isupper(c) numc-A+= _; for(i=0;i<26;i+) printf("大寫字母%c的個(gè)數(shù)是%dn", ); 3函數(shù)main()的功能是

11、:在帶頭結(jié)點(diǎn)的單鏈表中查找數(shù)據(jù)域中值最小的結(jié)點(diǎn).請(qǐng)?zhí)羁?include <stdio.h>struct node int data;struct node *next;int min(struct node *first)/*指針first為鏈表頭指針*/ strct node *p; int m; p= ; m= ; p=p->next; for(;p!=NULL;p=_) if(p->data<m) ; return m;二、程序閱讀題1寫出下面程序運(yùn)行的輸出結(jié)果( 6 分)#include <stdio.h>void main() int i,j

12、; for(i=3;i>=1;i-) for(j=1;j<=2;j+) printf("%d",i+j); printf("n"); 2寫出下面程序的輸出結(jié)果( 3 分) #include <stdio.h>int fun(int a,int b) if(b=0) return a; else return (fun(-a,-b);main() printf("%dn",fun(4,2);3. 寫出輸出結(jié)果是多少。( 5 分)#include <stdio.h>main() int j,a=1,3,

13、5,7,9,11,13,15,*p=a+5; for(j=3; j ;j-) switch(j) case 1: case 2: printf("%dn",(*p)+);break; case 3: printf("%dn",*(p-); 4. 寫出輸出結(jié)果是多少。( 6 分)#include <stdio.h>void fun1(char*p) char *q; q=p; while(*q!='0') (*q)+; q+; main()char a="Program",*p; p=&a3; fun

14、1(p); printf("%sn",a);三、改錯(cuò)題(20分)include <stdio.h>int isprime()int i;for(i=2,i<=n;i+) if(n%i=0) return 0;return 1;void main()int i,j;printf("primes from 1 to 100:n");for(i=2;j=0;i<=100;i+);if(isprime(i)printf("%d ,i ");j+;IF(j%5=0) printf("n");四、編程(

15、共 40 分)。1編寫一個(gè)程序,將主函數(shù)給出的一個(gè)有序數(shù)組,利用編寫的二分法(折半法)查找函數(shù),查找主函數(shù)給出的數(shù),如找到,返回?cái)?shù)組的下標(biāo)。主程序的框架以及部分代碼給出,二分法的函數(shù)原型也已給出。(本題 20 分)#include <stdio.h>#define SIZE 10/* function prototypes */int binarySearch( int *p, int searchKey, int low, int high );/* function main begins program execution */int main( void ) int a SIZE = 88,77,66,55,44,33,22,11,8,2 ; /* create array a */ int key; /* value to locate in array a */ printf( "Enter a number between 0 and 88: " ); scanf( "%d", &key );. /* end main */ 2. 請(qǐng)編寫函數(shù) sum_fact(number),返

溫馨提示

  • 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ù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 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)論