版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、C語言課程綜合復(fù)習(xí)資料一、單選題1. 在C語言中,字符型數(shù)據(jù)在內(nèi)存中的存儲(chǔ)形式是 A)原碼 B)補(bǔ)碼 C)反碼 D)ASCII碼2. 在C語言中,十進(jìn)制數(shù)47可等價(jià)地表示為A) 2f B) 02f C) 57 D) 057 3. 設(shè)有定義:int x=12,n=5; 則表達(dá)式 x%=(n%2) 的值為 A) 0 B) 1 C) 2 D) 34. 設(shè)有定義語句:char str20=,"Beijing","中國石油大學(xué)",*p=str; 則printf("%dn",strlen(p+20); 輸出結(jié)果是A)10 B) 6 C) 0 D)
2、 205. 已定義以下函數(shù): fun(int *p) return *p; 該函數(shù)的返回值是 A)不確定的值 B)形參p所指存儲(chǔ)單元中的值C)形參p中存放的值 D)形參p的地址值6. C語言中,函數(shù)返回值的類型是由A)return語句中的表達(dá)式類型決定B)調(diào)用函數(shù)的主調(diào)函數(shù)類型決定C)調(diào)用函數(shù)時(shí)的臨時(shí)類型決定 D)定義函數(shù)時(shí)所指定的函數(shù)類型決定7. 有以下函數(shù)定義: void fun( int n , double x ) 若以下選項(xiàng)中的變量都已正確定義并賦值,則對(duì)函數(shù)fun的正確調(diào)用語句是 A) fun( int y , double m ); B) k=fun( 10 , 12.5 );C
3、) fun( 10 , 12.5 ); D) void fun( 10 , 12.5 );8. 以下選項(xiàng)中不能正確賦值的是A) char b=H,e,l,l,o,!;B) char b10;b="Hello!";C) char b10= "Hello!";D) char *str="Hello!";9. 若有以下定義:char s20= "programming",*ps=s;則不能代表字符g的表達(dá)式是A) ps+3 B)s3 C) ps3 D) ps+=3,*ps10. 當(dāng)對(duì)兩個(gè)字符串進(jìn)行比較時(shí),應(yīng)該使用的函數(shù)是
4、A) strcat B) strcmp C) strcpy D) strlen11. 若i為整型變量,則以下循環(huán)的次數(shù)是for(i=2;i=0;)printf(“%d”,i-); A) 無限次 B) 0次 C) 1次 D) 2次12. 以下關(guān)于數(shù)組的描述正確的是A) 數(shù)組大小固定,但是可以有不同類型的數(shù)組元素B) 數(shù)組大小可變,但是所有數(shù)組元素的類型必須相同C) 數(shù)組大小固定,所有元素的類型必須相同D) 數(shù)組大小可變,可以有不同類型的數(shù)組元素13. 以下能正確定義數(shù)組并正確賦初值的語句是 A)int N=5,bNN; B)int a12=1,3; C)int c2= 1,2,3,4; D)in
5、t d32=1,2,34;14. 設(shè)有定義 int a =1,5,7,9,11,13, *p=a+3; 則*(p-2) , *(a+4) 的值是A)5 11 B)1 9 C)5 9 D)有錯(cuò)誤15. 已知char b5,*p=b; ,則正確的賦值語句是A)b=“abcd” ; B)*b=“abcd”; C) p=“abcd”; D)*p=“abcd”;16. 用數(shù)組名作為函數(shù)調(diào)用時(shí)的實(shí)參,則實(shí)際傳遞給形參的是A)數(shù)組的第一個(gè)元素值 B)數(shù)組中全部元素值C)數(shù)組的首地址 D)數(shù)組的元素個(gè)數(shù)17. 以下敘述中不正確的是A)在不同的函數(shù)中可以使用相同名字的變量B)函數(shù)中的形式參數(shù)是局部變量C)在一個(gè)
6、函數(shù)內(nèi)定義的變量只在本函數(shù)范圍內(nèi)有效D)在一個(gè)函數(shù)內(nèi)的復(fù)合語句中定義的變量在本函數(shù)范圍內(nèi)有效18. 當(dāng)對(duì)兩個(gè)字符串進(jìn)行比較時(shí),應(yīng)該使用的函數(shù)是A) strcat B) strcmp C) strcpy D) strlen19. 有如下定義:long m;char c;float x;double y;則表達(dá)式c+m*x/y的值的類型是A) long B) char C) float D) double20. 假設(shè)已定義 char c8= "test"; int i; 則下面的輸出函數(shù)調(diào)用中錯(cuò)誤的是A) printf("%s",c); B) for(i=0
7、;i<8;i+) printf("%c",ci);C) puts(c) D) for(i=0;i<8;i+) puts(ci);21. 若有以下定義:char s20= "programming",*ps=s;則不能代表字符g的表達(dá)式是A) ps+3 B) s3 C) ps3 D) ps+=3,*ps22. 以下選項(xiàng)中不能正確賦值的是A) char b=H,e,l,l,o,??;B) char b10;b="Hello!";C) char b10= "Hello!";D) char *str="
8、Hello!";23. 有以下函數(shù)定義: void fun( int n , double x ) 若以下選項(xiàng)中的變量都已正確定義并賦值,則對(duì)函數(shù)fun的正確調(diào)用語句是_。 A) fun( int y , double m ); B) k=fun( 10 , 12.5 );C) fun( 10 , 12.5 ); D) void fun( 10 , 12.5 );24從變量的作用域來分,可分為全局變量和局部變量,形參是A)局部變量 B)全局變量 C) 靜態(tài)變量 D) 動(dòng)態(tài)變量二、讀程序,寫出程序的執(zhí)行結(jié)果1. #include <stdio.h>void main() i
9、nt x=1,2,3; int s,i,*p=x; s=1; for(i=0;i<3;i+) s*=*(p+i); printf(“%dn”,s);答案62#include <stdio.h>char fun(char *s)if( *s >= ¢a¢ && *s <= ¢z¢ ) *s=*s-32;return *s;void main()char a20="Welcome",*p,ch;for(p=a;*p!=¢0¢p+)ch=fun(p);putchar(ch);
10、答案WELCOME3#include <stdio.h>void main()int x=26587,x1,r,sum=0;x1=x;while(x>0)r=x%10;sum+=r;x/=10;printf( "Sum of the digits in %d is %d", x1,sum);答案Sum of the digits in 26587 is 284#include <stdio.h>int fun(int x)int y=1;static int z=4;z+=1;+y;return(x+y+z); void main()int i
11、;for(i=1;i<=3;i+)printf("%3d",fun(i);8 10 125#include <stdio.h>void main() int x=3,y=4; int j;for(j=1 ; y>0 ; y - ) j=j*x;printf(“j=%dn”,j);運(yùn)行結(jié)果:j=816#include <stdio.h>void main() int x,y; for(y=1,x=1; y<=20;y+) if(x>=8) break; if(x%2=1) x+=5; continue ; x-=3; print
12、f("x=%d, y=%dn",x,y); 運(yùn)行結(jié)果:x=8,y=47 #include <stdio.h>void main() char x="language"char *ptr=x;while(*ptr) printf("%cn",*ptr-32); ptr+; 運(yùn)行結(jié)果:LANGUAGE8. #include <stdio.h> void main() int x=5,6,7; int s=1,i,*p=x; for(i=0;i<3;i+) s*=*(p+i); printf(“%dn”,s);
13、運(yùn)行結(jié)果:2109#include <stdio.h>int fun(int x) return(x>0 ? x : -x);void main() int a=12; printf(“%d, %dn”,a,fun(a) ;運(yùn)行結(jié)果:12,1210 #include <stdio.h>void ex( ) static int x=3 ; -x ; printf(“%d”,x) ; void main ( ) ex( ); ex( ); 運(yùn)行結(jié)果:2111. #include <stdio.h>void main() int i=0,a=0;while
14、( i<20 ) for(;)if(i%10)= =0) break;else i- -; i+=11; a+=i; printf("%dn",a);3212#include <stdio.h>void main()int a34=1,2,3,4,9,7,10,6,-1,8,-5,5;int i,j,row=0,colum=0,max;max=a00;for(i=0;i<=2;i+)for(j=0;j<=3;j+)if(aij>max)max=aij;row=i;colum=j;printf("max=%d,row=%d,col
15、um=%d",max,row,colum);max=10 ,row=1,colum=213. #include <stdio.h>int f(int b, int m,int n) int i,s=0; for(i=m;i<n;i+=2) s+=bi ; return s; void main() int x, a=1,2,3,4,5,6,7,8,9,10; x=f(a,3,8); printf("%dn",x); 1814#include <stdio.h>void swap(int b) int *p,*p1,*p2; p1=&a
16、mp;b0 ;p2=&b1;p=p1; p1=p1+1; p2=p;void main() int a=5,9;printf("%d,%dn",*a,*(a+1); swap(a); printf("%d,%dn",a0,a1);5,915. #include <stdio.h>int b=3;int fun(int *a) b+=*a; return(b);void main() int a=2, b=2; b+=fun(&a);printf(“%dn”,b); 716. #include <stdio.h>vo
17、id main() int a10,*p,*s,i; for(i=0;i<10;i+) scanf(%d”,a+i); for(p=a,s=a;p-a<10;p+) if(*p>*s)s=p; printf(“max=%d,index=%dn”,*s, s-a);簡述上列程序完成的功能:查找數(shù)組中最大值并記錄元素下標(biāo)17 #include <stdio.h>void main() int x,y; for(y=1,x=1; y<=20;y+) if(x>=8) break;if(x%2=1) x+=5; continue ; x-=3; printf(
18、“x=%d, y=%dn”,x ,y); 運(yùn)行結(jié)果:x=8,y=418 #include <stdio.h>#define N 3void zz(int xNN) int i,j,t;for(i=0;i<N;i+)for(j=0;j<i;j+) t=xij; xij=xji; xji=t; void main() int strNN=1,2,3,4,5,6,7,8,9, i,j; zz(str);for(i=0;i<N;i+) for(j=0;j<N;j+) printf(“%3d”,strij) ;printf("n") ; 運(yùn)行結(jié)果:
19、1 4 7 2 5 83 6 919#include <stdio.h>void main ( ) char a20= "abcXYZ", c ; int i, j;j= strlen(a)-1 ; for (i=0; j>i; i+,j-) c=*(a+i); *(a+i)=*(a+j); *(a+j)=c; puts(a); 運(yùn)行結(jié)果:ZXYcba20 #include <stdio.h>int a=100,b=200;void f( ) printf(“%d,%dn”,a,b); a=1;b=2; void main() int a=5,
20、b=7 ; f( );printf(“%d,%dn”, a,b) ; 運(yùn)行結(jié)果:5,721 #include <stdio.h>int d=1 ;int fun(int p) static int d=3 ; d+=p; printf("%3d" , d) ; return(d) ; void main( ) printf("%3dn" , fun(2+fun(d) ; 運(yùn)行結(jié)果:5,12,1222#include <stdio.h>void main() char x="123456789",*p=x ; i
21、nt i=0; while(*p) if(i%2=0) *p='*; p+; i+; puts(x);運(yùn)行結(jié)果:*2*4*6*8*三、編程題1編程輸入實(shí)數(shù)x,計(jì)算下面函數(shù)的值,并輸出y值。 x 2 x<1 y= 3x-1 1 £ x £ 10 x > 10程序結(jié)果:#include <stdio.h>void main() int x,y; scanf(“%d”,&x); if(x<1) y=x*x; else if(x>=1&&x<=10)y=3*x-1; else y=x/5; printf(“x
22、=%d,y=%dn”,x,y); 2編寫一個(gè)函數(shù),由實(shí)參傳來一個(gè)字符串,統(tǒng)計(jì)此字符串中字母、數(shù)字、空格和其他字符的個(gè)數(shù),并輸出統(tǒng)計(jì)結(jié)果。程序結(jié)果:#include<stdio.h>#include<conio.h>void main() /*主函數(shù)*/char c;
23、; /*定義變量*/int m=0,n=0,a=0,b=0;printf("請(qǐng)輸入任意字符串.n"); /*輸入提示部分,提示輸入*/while(c=getchar()!='n') /*循環(huán)語句,將由鍵盤輸入的非
24、39;n'字符賦值給c*/ if(c>=65&&c<=90)|(c>=97&&c<=122) /*第一個(gè)選擇語句,統(tǒng)計(jì)英文字符個(gè)數(shù)*/ m=m+1; else if(c=32)
25、0; /*第二個(gè)選擇語句,統(tǒng)計(jì)空格字符的個(gè)數(shù)*/ n=n+1; else if(c>=48&&c<=57)
26、60; /*第三個(gè)選擇語句,統(tǒng)計(jì)數(shù)字字符的個(gè)數(shù)*/ a=a+1; else
27、60; /*統(tǒng)計(jì)其他字符的個(gè)數(shù)*/ b=b+1;printf("%d%d%d%d",m,a,n,b); /*輸出最后統(tǒng)計(jì)結(jié)果*/
28、0; getch(); /*輸出結(jié)果后屏幕停留*/3. 編寫打印如下圖形的程序 (必須用循環(huán)語句實(shí)現(xiàn)) * * * * * * * * * * *程序結(jié)果:#includ
29、e<stdio.h> main( )int n,i,j;printf(“n=%dn”);scanf(“%d”,&n);for(i=0;i<n;i+) for(j=0;j<n-1-i;j+) Printf(“ ”); for(j=0;j<i+1;j+) Printf(“*”); printf(“n”);4. 編寫程序,從鍵盤上任意輸入20個(gè)整數(shù),存入一個(gè)數(shù)組中,然后輸出這些數(shù)中最大數(shù)及其下標(biāo)以及最小數(shù)及其下標(biāo)程序結(jié)果:#include<stdio.h> void main( )int a20,i,max,min,num1,num2;for(i=0
30、;i<20;i+)printf(“input the number%d:”,i);scanf(“%d”,&ai);printf(“n”);for(i=0;i<20;i+) If(ai<= a0) min=ai;Num1=i; Else max=ai;num2=i;printf(“min=%d,num1=%dn”,min,num1);printf(“max=%d,num2=%dn”,max,num2);5. 編程打印下列的楊輝三角形。(設(shè)8行) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 程序結(jié)果:#include <s
31、tdio.h>#define N 11void main() int i,j,aNN; /*數(shù)組為11行11列,0行0列不用*/ for(i=1;i<N;i+) ai1=1; /*使第1列元素的值為1*/ aii=1; /*使對(duì)角線元素的值為1*/ for(i=3;i<N;i+) /*從第3行開始處理*/ for(j=2;j<=i-1;j+) aij=ai-1j-1+ai-1j; for(i=1;i<N;i+) /*輸出數(shù)組各元素的值*/ for(j=1;j<=i;j+) printf(“%6d”,aij); printf(“n”); printf(“n”)
32、; 6求分段函數(shù)的值 程序結(jié)果:#include<stdio.h> #inclde<math.h>main() double x ,y; scanf(“%lf”,&x); if(x<0) y=log(x*x); else if(x=0) y=1;else y=1+exp(x);printf(“Y=%lf”,y);7編程打印以下圖形 (要求用循環(huán)控制語句實(shí)現(xiàn)) & & & & & & & & & & & & & & & & &
33、; & & & &程序結(jié)果#include<stdio.h>main()int i,j;for(i=1;i<=6;i+)for(j=1;j<=6-i;j+)printf(" ");for(j=1;j<=i;j+)printf("& ");printf("n");:C語言課程綜合復(fù)習(xí)資料答案一、單選題:1D 2D 3A 4A 5D 6B 7C 8B 9A 10B 11B 12C 13D 14A 15C 16C 17D 18B 19D 20D 21A 22B 23C 2
34、4A二、讀程序?qū)懗龀绦驁?zhí)行結(jié)果:1、62、WELCOME3、Sum of the digits in 26587 is 284、8 10 125、j=81 6、x=8,y=4 7、LANGUAGE8、210 9、12,12 10、2111、32 12、max=10,row=1,colum=2 13、18 14、5,9 15、7 16、查找數(shù)組中最大值并記錄元素下標(biāo)17、x=8,y=418、1 4 7 19、ZYXcba2 5 8 20、5,73 6 9 21、5,12,1222、*2*4*6*8*三、編程題1、#include <stdio.h>void main() int x,
35、y; scanf(“%d”,&x); if(x<1) y=x*x; else if(x>=1&&x<=10)y=3*x-1; else y=x/5; printf(“x=%d,y=%dn”,x,y); 2. #include<stdio.h>#include<conio.h>void main()
36、0; /*主函數(shù)*/char c; /*定義變量*/int m=0,n=0,a=0,b=0;printf("請(qǐng)輸入任意字符串.n"); /*輸入提示部分,提示輸入*/while(c=getchar()!='n')
37、160; /*循環(huán)語句,將由鍵盤輸入的非'n'字符賦值給c*/ if(c>=65&&c<=90)|(c>=97&&c<=122) /*第一個(gè)選擇語句,統(tǒng)計(jì)英文字符個(gè)數(shù)*/ m=m+1; else if(c=32)
38、 /*第二個(gè)選擇語句,統(tǒng)計(jì)空格字符的個(gè)數(shù)*/ n=n+1; else if(c>=48&&c<=57)
39、; /*第三個(gè)選擇語句,統(tǒng)計(jì)數(shù)字字符的個(gè)數(shù)*/ a=a+1; else
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年版在線教育平臺(tái)合作開發(fā)合同4篇
- 2025年度醫(yī)療衛(wèi)生機(jī)構(gòu)專業(yè)技術(shù)人員聘用合同4篇
- 二零二五年度殯葬服務(wù)與社區(qū)養(yǎng)老服務(wù)對(duì)接合同3篇
- 2025年度農(nóng)副產(chǎn)品線上線下銷售與物流一體化服務(wù)合同3篇
- 二零二五年度投資收益分成合同
- 2025版高端定制門窗工程承攬合同3篇
- 2025年度企業(yè)會(huì)計(jì)人員專項(xiàng)聘用合同范本
- 2025年度票據(jù)質(zhì)押資產(chǎn)證券化專項(xiàng)合同4篇
- 二零二五年度戶外木制品加工承包合同2篇
- 2025年度面粉行業(yè)二零二五年度面粉產(chǎn)品追溯體系共建合同3篇
- 江蘇省蘇州市2024-2025學(xué)年高三上學(xué)期1月期末生物試題(有答案)
- 銷售與銷售目標(biāo)管理制度
- 人教版(2025新版)七年級(jí)下冊(cè)英語:寒假課內(nèi)預(yù)習(xí)重點(diǎn)知識(shí)默寫練習(xí)
- 2024年食品行業(yè)員工勞動(dòng)合同標(biāo)準(zhǔn)文本
- 2025年第一次工地開工會(huì)議主要議程開工大吉模板
- 全屋整裝售后保修合同模板
- 高中生物學(xué)科學(xué)推理能力測(cè)試
- GB/T 44423-2024近紅外腦功能康復(fù)評(píng)估設(shè)備通用要求
- 2024-2030年中國減肥行業(yè)市場發(fā)展分析及發(fā)展趨勢(shì)與投資研究報(bào)告
- 運(yùn)動(dòng)技能學(xué)習(xí)
- 單側(cè)雙通道內(nèi)鏡下腰椎間盤摘除術(shù)手術(shù)護(hù)理配合1
評(píng)論
0/150
提交評(píng)論