哈工大2008 年秋 季學(xué)期C語言試題一_第1頁
哈工大2008 年秋 季學(xué)期C語言試題一_第2頁
哈工大2008 年秋 季學(xué)期C語言試題一_第3頁
哈工大2008 年秋 季學(xué)期C語言試題一_第4頁
哈工大2008 年秋 季學(xué)期C語言試題一_第5頁
已閱讀5頁,還剩15頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

班級:學(xué)號:姓名:PAGE18第1頁(共10頁)班號姓名哈工大2008年秋季學(xué)期C語言試題題號一二三四五六卷面總分分?jǐn)?shù)說明:本試卷卷面滿分為100分??偝煽儗雌綍r實驗成績、機考成績和卷面筆試成績各自所占比例折合后累加計算。一、判斷對錯(6分,每題1分,對:√,錯:×)1.函數(shù)的定義可以嵌套,但函數(shù)的調(diào)用不可以嵌套。()2.C語言程序總是從main函數(shù)第一條可執(zhí)行語句開始執(zhí)行,在main函數(shù)結(jié)束。()3.若用數(shù)組名作為函數(shù)的實參,傳遞給形參的是數(shù)組第一個元素的值。()4.C語言中,函數(shù)調(diào)用時,只有當(dāng)實參與其對應(yīng)的形參同名時,才共占同一個存儲單元。()5.凡是函數(shù)中未指定存儲類別的局部變量其隱含的存儲類別是自動(auto)變量。()6.結(jié)構(gòu)體類型所占用的內(nèi)存字節(jié)數(shù)是所有成員變量占用的內(nèi)存字節(jié)數(shù)的總和。()二、單項選擇題:(10分,每題2分)1.若有定義int(*p)[4],則標(biāo)識符p是一個。A)指向整型變量的指針變量B)指向函數(shù)的指針變量C)指向有四個整型元素的一維數(shù)組的指針變量D)指針數(shù)組名,有四個元素,每個元素均為一個指向整型變量的指針2.下列對字符串的定義中,錯誤的是:。A)charstr[7]="FORTRAN";B)charstr[]="FORTRAN";C)char*str="FORTRAN";D)charstr[]={'F','O','R','T','R','A','N',0};3.針對下面程序段,下面哪些說法是正確的?#include<stdio.h>voidSwap(int*x,int*y);main(){inta,b;a=5;b=9;Swap(&a,&b);printf("a=%d,b=%d",a,b);}voidSwap(int*x,int*y){int*pTemp;*pTemp=*x;*x=*y;*y=*pTemp;}A)程序運行結(jié)果為亂碼;B)程序運行后將導(dǎo)致程序崩潰;C)程序編譯時出錯導(dǎo)致程序無法運行;D)程序執(zhí)行了危險的操作;4.已知學(xué)生記錄描述為:structstudent{ int no; char name[20]; char sex; struct { int year; char month[15]; int day; }birth;}; structstudents;設(shè)變量s中的生日是1984年11月11日,下列對生日的正確賦值方式是_____A)s.birth.year=1984;s.birth.month="11";s.birth.day=11;B)s.birth.year=1984;s.birth.month=11;s.birth.day=11;C)s.birth.year=1984;strcpy(s.birth.month,"11");s.birth.day=11;D)s.birth.year=1984;strcpy(s.birth.month,11);s.birth.day=11;5.要使下面程序輸出1,2,34,則從鍵盤輸入的數(shù)據(jù)格式應(yīng)為。#include<stdio.h>main(){ chara,b;intc; scanf("%c%c%d",&a,&b,&c); printf("%c,%c,%d\n",a,b,c);}A)1234 B)1,2,34C)’1’,’2’,34 D)1234三、寫出下列程序的運行結(jié)果。(10分,每題2分)1.#include<stdio.h>main(){ inti,j,x=0; for(i=0;i<2;i++) { x++; for(j=0;j<3;j++) { if(j%2)break; x++; } x++; }printf("x=%d\n",x);}程序運行結(jié)果是:2.#include<stdio.h>structdate{intyear;intmonth;intday;};structdatefunc(structdatep){p.year=2000;p.month=5;p.day=22;returnp;}main(){structdated;d.year=1999;d.month=4;d.day=23;printf("%d/%d/%d\n",d.year,d.month,d.day);d=func(d);printf("%d/%d/%d\n",d.year,d.month,d.day);}程序運行結(jié)果是:3.#include<stdio.h>main(){chara[]="Hello";char*p=NULL;for(p=a;p<a+5;p++){ printf("%s\n",p);}}程序運行結(jié)果是:4.#include<stdio.h>intfun(intx,inty){ returnx>y?x:y;}main(){inta=2,b=5,c=8;printf("%d\n",fun(fun(a+c,b),a-c));} 程序運行結(jié)果是:5.#include<stdio.h>voidFunc(void);main(){ inti; for(i=0;i<5;i++) { Func(); }}voidFunc(void){ staticinta=1; intb=2,c; c=a+b; a++; b++; printf("%d\n",c);}程序運行結(jié)果是:四、閱讀程序,在標(biāo)有下劃線的空白處填入適當(dāng)?shù)谋磉_式或語句,使程序完整并符合題目要求。(10分,每空1分)先按學(xué)號由小到大的順序從鍵盤輸入學(xué)生的學(xué)號和成績,然后從鍵盤任意輸入一個學(xué)生的學(xué)號,查找并打印具有該學(xué)號的學(xué)生的成績。#include<stdio.h>#defineARR_SIZE40;main(){ floatscore[ARR_SIZE]; intn,i,pos; longnum[ARR_SIZE],x; printf("Pleaseentertotalnumber:"); scanf("%d",&n); printf("Pleaseenterthenumberandscore:\n"); for(i=0;i<n;i++) { scanf("%ld%f",&num[i],&score[i]); } printf("Pleaseenterthesearchingnumber:"); scanf("%ld",&x); pos=BinSearch(); if() { printf("score=%4.0f\n",score[pos]); } else { printf("Notfound!\n"); }}intBinSearch(longa[],intn,longx){ intlow,high,mid; low=0; high=n-1; while(low<=high) { mid=(high+low)/2; if(x>a[mid]) { low=; } elseif(x<a[mid]) { high=; } else { return(); } } return(-1);}2.輸入一行字符,統(tǒng)計其中的英文字符、數(shù)字字符、空格及其它字符的個數(shù)。#include<stdio.h>#include<string.h>#defineARR_SIZE80main(){ charstr[ARR_SIZE]; intlen,i,letter=0,digit=0,space=0,others=0; gets(str); for(i=0;;i++) { if() letter++;elseif() digit++;elseif() space++;else others++;}printf("Englishcharacter:%d\n",letter);printf("digitcharacter:%d\n",digit);printf("space:%d\n",space);printf("othercharacter:%d\n",others);}五、在下面給出的4個程序中,共有18處錯誤(包括語法錯誤和邏輯錯誤),請找出其中的錯誤,并改正之。(34分,每找對1個錯誤,加1分,每修改正確1個錯誤,再加1分。只要找對17處錯誤即可,多找不加分。)1.計算組合數(shù)(m≥n)#include<stdio.h>unsignedlongFactorial(unsignedintnumber);main(){ unsignedintm,n; doublep; do{ printf("Pleaseinputm,n:"); scanf("%d,%d",&m,&n); }while(m>=n); p=(double)Factorial(m)/Factorial(n)*Factorial(m-n); printf("p=%lf\n",p);}unsignedlongFactorial(unsignedintx){ unsignedlongi,result; for(i=2;i<=x;i++) result*=i; returnresult;}2.利用下面性質(zhì)計算最大公約數(shù):g(a,b)=g(a-b,b)a>bg(a,b)=g(a,b-a)a<bg(a,b)=a=ba=b#include<stdio.h>intMaxCommonFactor(inta,intb);main(){ inta,b,x; printf("Inputa,b:"); scanf("%d,%d",&a,&b); x=MaxCommonFactor(a,b); printf("MinCommonMultiple=%d\n",x);}intMaxCommonFactor(inta,intb);{ if(a<=0&&b<=0) return-1; while(a!=b) { if(a>b) { returna; } elseif(b>a) { returnb; } } } 3.輸入一個字符數(shù)小于100的不帶空格的字符串string,然后在string所保存字符串中的每個字符間加一個空格。#include<stdio.h>#defineMAX=100;voidCopyString(charc[],chars[]);voidInsert(chars[]);main(){ charstring[MAX]; scanf("%s",string); Insert(charstring[]); printf("%s",string);}voidCopyString(charc[],chars[]){ inti; for(i=0;s[i]!='\0';i++) { c[i]=s[i]; } c[i]='\0';}voidInsert(charsrcStr[]){ charstrTemp[MAX]; inti=0,j=0; CopyString(strTemp,srcStr); while(srcStr[i]!='\0') { srcStr[i]=strTemp[j]; i++; j++; srcStr[i]="";i++; }}4.下面函數(shù)實現(xiàn)兩個字符串大小的比較,函數(shù)將兩個字符串中第一個出現(xiàn)的不相同字符的ASII碼值之差作為比較的結(jié)果返回,當(dāng)兩個字符串完全一樣時,返回值為0。intMyStrcmp(char*p1,char*p2){ for(;*p1=*p2;p1++;p2++) { if(*p1='\0')return0; }returnp1-p2;}六、編程(30分)1.編程計算1!+2!+3!+……+10!的值。(12分)2.編程先輸入某班30個學(xué)生某門課的成績,對全班30個學(xué)生成績進行由高到低排序,并打印輸出排序結(jié)果,要求按照如下函數(shù)原型,用函數(shù)編程實現(xiàn)排序功能。(18分)voidSort(floatscore[],intn);參考答案與評分標(biāo)準(zhǔn)一、判斷對錯(6分,每題1分)1.函數(shù)的定義可以嵌套,但函數(shù)的調(diào)用不可以嵌套。(錯)2.C語言程序總是從main函數(shù)第一條可執(zhí)行語句開始執(zhí)行,在main函數(shù)結(jié)束。(正確)3.若用數(shù)組名作為函數(shù)的實參,傳遞給形參的是數(shù)組第一個元素的值。(錯)4.C語言中,函數(shù)調(diào)用時,只有當(dāng)實參與其對應(yīng)的形參同名時,才共占同一個存儲單元。(錯)5.凡是函數(shù)中未指定存儲類別的局部變量其隱含的存儲類別是自動(auto)變量。(正確)6.結(jié)構(gòu)體類型所占用的內(nèi)存字節(jié)數(shù)是所有成員變量占用的內(nèi)存字節(jié)數(shù)的總和。(錯誤)二、單項選擇題:(10分,每題2分,評分標(biāo)準(zhǔn):正確得2分,錯誤扣2分)1.若有定義int(*p)[4],則標(biāo)識符p是一個。A)指向整型變量的指針變量B)指向函數(shù)的指針變量√C)指向有四個整型元素的一維數(shù)組的指針變量D)指針數(shù)組名,有四個元素,每個元素均為一個指向整型變量的指針2.下列對字符串的定義中,錯誤的是:?!藺)charstr[7]="FORTRAN";B)charstr[]="FORTRAN";C)char*str="FORTRAN";D)charstr[]={'F','O','R','T','R','A','N',0};3.針對下面程序段,下面哪些說法是正確的?#include<stdio.h>voidSwap(int*x,int*y);main(){inta,b;a=5;b=9;Swap(&a,&b);printf("a=%d,b=%d",a,b);}voidSwap(int*x,int*y){int*pTemp;*pTemp=*x;*x=*y;*y=*pTemp;}A)程序運行結(jié)果為亂碼;B)程序運行后將導(dǎo)致程序崩潰;C)程序編譯時出錯導(dǎo)致程序無法運行;√D)程序執(zhí)行了危險的操作;4.已知學(xué)生記錄描述為:structstudent{ int no; char name[20]; char sex; struct { int year; char month[15]; int day; }birth;}; structstudents;設(shè)變量s中的生日是1984年11月11日,下列對生日的正確賦值方式是_____A)s.birth.year=1984;s.birth.month="11";s.birth.day=11;B)s.birth.year=1984;s.birth.month=11;s.birth.day=11;√C)s.birth.year=1984;strcpy(s.birth.month,"11");s.birth.day=11;D)s.birth.year=1984;strcpy(s.birth.month,11);s.birth.day=11;5.要使下面程序的輸出1,2,34,則從鍵盤輸入的數(shù)據(jù)格式應(yīng)為。#include<stdio.h>main(){ chara,b;intc; scanf("%c%c%d",&a,&b,&c); printf("%c,%c,%d\n",a,b,c);}A)1234 B)1,2,34C)’1’,’2’,34 √D)1234三、寫出下列程序的運行結(jié)果。(10分,評分標(biāo)準(zhǔn):正確得2分,完全錯誤扣2分,如果部分錯誤,少一行或者多了一行,或者其他提示信息,則扣1分)1.main(){ inti,j,x=0; for(i=0;i<2;i++) { x++; for(j=0;j<3;j++) { if(j%2)continue; x++; } x++; }printf("x=%d\n",x);}程序運行結(jié)果是:x=62.#include<stdio.h>structdate{intyear;intmonth;intday;};structdatefunc(structdatep){p.year=2000;p.month=5;p.day=22;returnp;}main(){structdated;d.year=1999;d.month=4;d.day=23;printf("%d/%d/%d\n",d.year,d.month,d.day);d=func(d);printf("%d/%d/%d\n",d.year,d.month,d.day);}程序的運行結(jié)果是:1999/4/232000/5/223.#include<stdio.h>main(){chara[]="Hello";char*p=NULL;for(p=a;p<a+5;p++){ printf("%s\n",p);}}程序運行結(jié)果是:Helloellolloloo4.#include<stdio.h>intfun(intx,inty){ returnx>y?x:y;}main(){inta=2,b=5,c=8;printf("%d\n",fun(fun(a+c,b),a-c));} 程序運行結(jié)果是:105.#include<stdio.h>voidFunc(void);main(){ inti; for(i=0;i<5;i++) { Func(); }}voidFunc(void){ staticinta=1; intb=2,c; c=a+b; a++; b++; printf("%d\n",c);}程序運行結(jié)果是:34567四、閱讀程序,在標(biāo)有下劃線的空白處填入適當(dāng)?shù)谋磉_式或語句,使程序完整并符合題目要求。(10分,評分標(biāo)準(zhǔn):每空1分,正確得1分,錯誤扣1分)1.先按學(xué)號由小到大的順序從鍵盤輸入學(xué)生的學(xué)號和成績,然后從鍵盤任意輸入一個學(xué)生的學(xué)號,查找并打印具有該學(xué)號的學(xué)生的成績。#include<stdio.h>#defineARR_SIZE40intBinSearch(longa[],intn,longx);main(){ floatscore[ARR_SIZE]; intn,i,pos; longnum[ARR_SIZE],x; printf("Pleaseentertotalnumber:"); scanf("%d",&n); printf("Pleaseenterthenumberandscore:\n"); for(i=0;i<n;i++) { scanf("%ld%f",&num[i],&score[i]); } printf("Pleaseenterthesearchingnumber:"); scanf("%ld",&x); pos=BinSearch(num,n,x); if(pos!=-1) { printf("score=%4.0f\n",score[pos]); } else { printf("Notfound!\n"); }}intBinSearch(longa[],intn,longx){ intlow,high,mid; low=0; high=n-1; while(low<=high) { mid=(high+low)/2; if(x>a[mid]) { low=mid+1; } elseif(x<a[mid]) { high=mid-1; } else { return(mid); } } return(-1);}2.輸入一行字符,統(tǒng)計其中的英文字符、數(shù)字字符、空格及其它字符的個數(shù)。#include<stdio.h>#include<string.h>#defineARR_SIZE80main(){ charstr[ARR_SIZE]; intlen,i,letter=0,digit=0,space=0,others=0; gets(str); for(i=0;str[i]!='\0';i++) { if(str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z') letter++;elseif(str[i]>='0'&&str[i]<='9') digit++;elseif(str[i]=='') space++;else others++;}printf("Englishcharacter:%d\n",letter);printf("digitcharacter:%d\n",digit);printf("space:%d\n",space);printf("othercharacter:%d\n",others);}五、在下面給出的4個程序中,共有18處錯誤(包括語法錯誤和邏輯錯誤),請找出其中的錯誤,并改正之。(34分,每找對1個錯誤,加1分,每修改正確1個錯誤,再加1分。只要找對17個即可,多找不加分。)1.計算組合數(shù)(m≥n)(4個錯)#include<stdio.h>unsignedlongFactorial(unsignedintnumber);main(){ unsignedintm,n; doublep; do{ printf("Pleaseinputm,n(m>=n):"); scanf("%d,%d",&m,&n);//"%u,%u" }while(m>=n);//應(yīng)該為(m<n); p=(double)Factorial(m)/Factorial(n)*Factorial(m-n);//p=(double)Factorial(m)/(Factorial(n)*Factorial(m-n)); printf("p=%f\n",p);}unsignedlongFactorial(unsignedintx){ unsignedlongi,result;//result=1 for(i=2;i<=x;i++) result*=i; returnresult;}2.利用下面性質(zhì)計算最大公約數(shù):(5個錯)g(a,b)=g(a-b,b)a>b;g(a,b)=g(a,b-a)a<b;g(a,b)=a=ba=b#include<stdio.h>intMaxCommonFactor(inta,intb);main(){ inta,b,x; printf("Inputa,b:"); scanf("%d,%d",&a,&b); x=MaxCommonFactor(a,b); printf("MinCommonMultiple=%d\n",x);}intMaxCommonFactor(inta,intb);//去掉;{ if(a<=0&&b<=0) //if(a<=0||b<=0) return-1; while(a!=b) { if(a>b) { returna;//a=a-b; } elseif(b>a) { returnb;//b=b-a; } } //returna;} 3.輸入一個字符數(shù)小于100的不帶空格的字符串string,然后在string所保存字符串中的每個字符間加一個空格。(5個錯)#include<stdio.h>#defineMAX=100;//#defineMAX100voidCopyString(charc[],chars[]);voidInsert(chars[]);main(){ charstring[MAX]; scanf("%s",string); Insert(charstring[]);//Insert(string); printf("%s",string);}voidCopyString(charc[],chars[]){ inti; for(i=0;s[i]!='\0';i++) { c[i]=s[i]; } c[i]='\0';}voidInsert(charsrcStr[]){ charstrTemp[MAX]; inti=0,j=0; CopyString(strTemp,srcStr); while(srcStr[i]!='\0')//while(strTemp[j]!='\0') { srcStr[i]=strTemp[j]; i++; j++; srcStr[i]="";//srcStr[i]='';i++; } //srcStr[i]='\0';}4.下面函數(shù)實現(xiàn)兩個字符串大小的比較,函數(shù)將兩個字符串中第一個出現(xiàn)的不相同字符的ASII碼值之差作為比較的結(jié)果返回當(dāng)兩個字符串完全一樣時,返回值為0。(4個錯)intMyStrcmp(char*p1,char*p2){ for(;*p1=*p2;p1++

;p2++)//for(;*p1==*p2;p1++

,p2++)兩個錯 { if(*p1='\0')return0;//if(*p1=='\0')return0; }returnp1-p2;//return*p1-*p2;}六、編程(30分)總的原則:每出現(xiàn)一處簡單語法錯誤就扣1分,具體評分標(biāo)準(zhǔn)見各題。1.編程計算1!+2!+3!+……+10!的值。(12分)參考答案1:#include<stdio.h>main(){ longterm=1,sum=0;//2 inti; for(i=1;i<=10;i++)//2 { term=term*i;//3 sum=sum+term;//3 } printf("1!+2!+...+10!=%ld\n",sum);//2}參考答案2:#include<stdio.h>main(){ longterm,sum=0;//2 inti,j; for(i=1;i<=10;i++)//1 { term=1;//2 for(j=1;j<=i;j++)//1 { term=term*j;//2 } sum=sum+term;//2 } printf("1!+2!+…+10!=%ld\n",sum);//2}2.編程先輸入某班30個學(xué)生某門課的成績,對全班30個學(xué)生成績進行由高到低排序,并打印輸出排序結(jié)果,要求用函數(shù)編程實現(xiàn)排序功能。(18分)答案1:#include<stdio.h>//1voidSort(floatscore[],intn);//1main()//1{ floatscore[30],temp;//1 intn=30,i,j; //1 printf("Pleaseenterthenumberandscore:\n"); for(i=0;i<n;i++)//1 { scanf("%f",&score[i])

溫馨提示

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

最新文檔

評論

0/150

提交評論