C語言練習題及答案_第1頁
C語言練習題及答案_第2頁
C語言練習題及答案_第3頁
C語言練習題及答案_第4頁
C語言練習題及答案_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、單項選擇題:1( a )是構(gòu)成c語言程序的基本單位。a、函數(shù) b、過程 c、子程序 d、子例程2c語言程序從 c 開始執(zhí)行。 a) 程序中第一條可執(zhí)行語句 b) 程序中第一個函數(shù)c) 程序中的main函數(shù) d) 包含文件中的第一個函數(shù)3、以下說法中正確的是( c )。 a、c語言程序總是從第一個定義的函數(shù)開始執(zhí)行 b、在c語言程序中,要調(diào)用的函數(shù)必須在main( )函數(shù)中定義 c、c語言程序總是從main( )函數(shù)開始執(zhí)行 d、c語言程序中的main( )函數(shù)必須放在程序的開始部分4.下列關(guān)于c語言的說法錯誤的是( b ) 。a) c程序的工作過程是編輯、編譯、連接、運行 b) c語言不區(qū)分大

2、小寫。c) c程序的三種基本結(jié)構(gòu)是順序、選擇、循環(huán) d) c程序從main函數(shù)開始執(zhí)行5.下列正確的標識符是(c)。a.-a1 b.ai c.a2_i d.int t6下列c語言用戶標識符中合法的是( b )。 a)3ax b)x c)case d)-e2 e)union7下列四組選項中,正確的c語言標識符是( c )。a) %x b) a+b c) a123 d) 1238、下列四組字符串中都可以用作c語言程序中的標識符的是( a )。 a、print _3d db8 abc b、iam one_half start$it 3pai c、str_1 cpp pow while d、pxq m

3、y-book line# his.age 9.c語言中的簡單數(shù)據(jù)類型包括(d )。 a、整型、實型、邏輯型 b、整型、實型、邏輯型、字符型 c、整型、字符型、邏輯型 d、整型、實型、字符型10.在c語言程序中,表達式5%2的結(jié)果是 c 。 a)2.5 b)2 c)1 d)311如果int a=3,b=4;則條件表達式ab? a:b的值是_a_。a) 3 b) 4 c) 0 d) 112若int x=2,y=3,z=4 則表達式xage d) (*p).age33.設(shè)有如下定義:struck sk int a;float b;data;int *p;若要使p指向data中的a域,正確的賦值語句是

4、 c a) p=&a;b) p=data.a;c) p=&data.a;d)*p=data.a;34.設(shè)有以下說明語句: typedef struct stu int a; float b; stutype; 則下面敘述中錯誤的是( d )。 a、struct是結(jié)構(gòu)類型的關(guān)鍵字 b、struct stu是用戶定義的結(jié)構(gòu)類型 c、a和b都是結(jié)構(gòu)成員名d、stutype是用戶定義的結(jié)構(gòu)體變量名35 語句int *p;說明了 c 。a)p是指向一維數(shù)組的指針 b)p是指向函數(shù)的指針,該函數(shù)返回一int型數(shù)據(jù)c)p是指向int型數(shù)據(jù)的指針 d)p是函數(shù)名,該函數(shù)返回一指向int型數(shù)據(jù)的指針36下列不正

5、確的定義是(a )。a. int *p=&i,i; b.int *p,i;cint i,*p=&i; d.int i,*p;37. 若有說明:int n=2,*p=&n,*q=p,則以下非法的賦值語句是: (d )a)p=q b)*p=*q c)n=*q d)p=n38有語句:int a10,;則 b 是對指針變量p的正確定義和初始化。a)int p=*a; b)int *p=a; c)int p=&a; d)int *p=&a;39.若有說明語句“int a5,*p=a;”,則對數(shù)組元素的正確引用是( c )。a.ap b.pa c.*(p+2) d.p+240. 有如下程序int a10=

6、1,2,3,4,5,6,7,8,9,10,*p=a;則數(shù)值為9的表達式是 b a) *p+9 b) *(p+8) c) *p+=9 d) p+841. 在c語言中,以 d 作為字符串結(jié)束標志a)n b) c) 0 d)0 42.下列數(shù)據(jù)中屬于“字符串常量”的是(a )。a.“a” b.abc c.abc0 d.a43.已知char x=hello, y=h,e,a,b,e;, 則關(guān)于兩個數(shù)組長度的正確描述是 b .a)相同 b)x大于y c)x小于y d)以上答案都不對44. 下面各函數(shù)中能實現(xiàn)打開文件功能的是 a a) fopen b) fgetc c) fputcd) fclose45.

7、下列語句中,把變量fp說明為一個文件型指針的是( a ) 。a) file *fp; b) file fp;c) file *fp; d) file fp;46以讀寫方式打開一個已有的文本文件file1,并且file *fp,下面fopen函數(shù)正確的調(diào)用方式是( b )。a.fp=fopen(“file1”,“r”)b.fp=fopen(“file1”,“r+”)c.fp=fopen(“file1”,“rb”)d.fp=fopen(“file1”,“w”)一、 讀程序基本輸入輸出及流程控制1.#include main() int a=1,b=3,c=5;if (c=a+b) printf(y

8、esn);else printf(non);運行結(jié)果為:no2. #include main() int a=12, b= -34, c=56, min=0;min=a; if(minb) min=b; if(minc) min=c;printf(min=%d, min);運行結(jié)果為: min=-343.#include main() int x=2,y= -1,z=5; if(xy)if(y0) z=0;else z=z+1; printf(“%dn”,z); 運行結(jié)果為:54. #include main() float a,b,c,t;a=3;b=7;c=1;if(ab) t=a;a=b

9、;b=t;if(ac) t=a;a=c;c=t;if(bc) t=b;b=c;c=t;printf(%5.2f,%5.2f,%5.2f,a,b,c); 運行結(jié)果為:1.00, 2.00, 7.005#include main ( ) float c=3.0 , d=4.0;if ( cd ) c=5.0;else if ( c=d ) c=6.0;else c=7.0; printf ( “%.1fn”,c ) ;運行結(jié)果為:7.06.#include main()int m;scanf(%d, &m);if (m = 0) if (m%2 = 0)printf(%d is a positiv

10、e evenn, m); elseprintf(%d is a positive oddn, m);else if (m % 2 = 0) printf(%d is a negative evenn, m);else printf(%d is a negative oddn, m);若鍵入9,則運行結(jié)果為: -9 is a negative odd7. #include main() int num=0;while(num=2) num+;printf(%dn,num);運行結(jié)果為:1238#include main( ) int sum=10,n=1;while(n3) sum=sum-n;

11、 n+; printf(“%d,%d”,n,sum); 運行結(jié)果為:3,79.#include main() int num,c; scanf(%d,&num); do c=num%10; printf(%d,c); while(num/=10)0);printf(n); 從鍵盤輸入23,則運行結(jié)果為:3210#include main() int s=0,a=5,n;scanf(%d,&n);do s+=1; a=a-2; while(a!=n);printf(%d,%dn,s,a); 若輸入的值1,運行結(jié)果為: 2,1 11#include stdio.h main() char c; c

12、=getchar(); while(c!=?) putchar(c); c=getchar(); 如果從鍵盤輸入abcde?fgh(回車)運行結(jié)果為:abcde12#include main() char c; while(c=getchar()!=$) if(a=c&c=z) putchar(c); else if(a=c&c=z) putchar(c-32); 當輸入為ab*ab%cd#cd$時,運行結(jié)果為:ababcdcd13. #include main() int x, y =0;for(x=1;x=10) break; y=y+x; printf(“%d %d”,y,x);運行結(jié)果

13、為:10 514.#include main( ) char ch; ch=getchar( ); switch(ch) case a : printf(“%c”,a); case b : printf(“%c”,b); break; default: printf(“%sn”,”other”); 當從鍵盤輸入字母a時,運行結(jié)果為:ab15. #include main( ) int a=1,b=0; scanf(“%d”,&a);switch(a) case 1: b=1;break;case 2: b=2;break;default : b=10;printf(%d , b);若鍵盤輸入5

14、,運行結(jié)果為:1016. #include main()_ char grade=c; switch(grade) case a: printf(“90-100n”); case b: printf(“80-90n”);case c: printf(“70-80n”);case d: printf(“60-70n”); break;case e: printf(“60n”); default : printf(“error!n”); 運行結(jié)果為:70-8060-7017.#include main() int y=9; for(;y0;y- -)if(y%3=0) printf(%d”,- -y); continue;運行結(jié)果為:85218. #include main() int i,sum=0; i=1;do sum=sum+i; i+; while(i=10);printf(“%d”,sum);運行結(jié)果為: 5519.#include #define n 4main() int i; int x1=1,x2=2;printf(n);for(i=1;i=n;i+) printf(%4d%4d,x1,x2);if(i%2=0) printf(n);x1=x1+x2;x2=x2+x1;運行結(jié)果為:1 2 3 58 13

溫馨提示

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

評論

0/150

提交評論