




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
千里之行,始于足下讓知識(shí)帶有溫度。第第2頁/共2頁精品文檔推薦大一c語言期末試題及參考答案2022級(jí)信息學(xué)院《C語言設(shè)計(jì)》考試試題
一、推斷下列語句或程序的對(duì)錯(cuò)。10分√
1intx=y=z=’0’;(×)y,z沒有定義
2#include;(×)不能有分號(hào),#開始的結(jié)尾均不能有分號(hào);
3printf(“%s\n”,”clanguage”);(√)
4floata[100];
int*p=a;(×)數(shù)據(jù)類型不匹配
5charstr[20];
6intdata[4]={0,1,2,3,4};(×)五個(gè)元素,但是惟獨(dú)四個(gè)單元
7floatx=1.45e+310L;(×)數(shù)值越界
8intxyz-1=2;(×)
9intx=‘\xae’;(√)
10int*p,a[2][3];
p=a;(×)數(shù)據(jù)類型不匹配
二計(jì)算下列表達(dá)式的值10分
設(shè)unsignedinta=10,b=17,c=5,d=3;
floatf;
(1)f=b/c(3.0)
(2)!(a+b)+c-1添加函數(shù)原型聲明
main()
{
floata,b;
floatadd_reasult,sub_result;
scanf(“%f,%f”,a,b);
add_result=calculate(a,b,應(yīng)當(dāng)直接定義為變量floattemp;
sub=a*a-b*b;*sub=a*a-b*b;
temp=a*a+b*b;
return*temp;returntemp
}
(2)統(tǒng)計(jì)N個(gè)字符中大寫字母和數(shù)字字符的個(gè)數(shù)
#include
#defineN5
Count(char*str,int*result);添加函數(shù)聲明
main()
{
charstring[N][80];
chari;
intCapital_Count=0,Num_Count=0;需要初始化為0
for(i=0;i=’A’
If(str[I]>’0’||str[I]main()
{
floaty,s,x,d,t;
intn,I,j;
scanf(“%d%f”,
s=1.0;
____________________________;
for(I=2;I
#include
voidmain(void)
{
charstr[80]=”ABCdabcdfgabc”;
char*p;
p=my_strrstr(str,”abc”);
printf(“%s\n”,p);
p=my_strrstr(str,”“);
printf(“%s\n”,p);
}
char*my_strrstr(char*s1,char*s2)
{
char*last;
char*current;
_________________________;
if(________________________)
{
last=current=_____________;
While(______);
{
last=current;
current=_______;
}
}
returnlast;
}
五.寫輸出結(jié)果(20分)
(1)
#include
voidfun(int*,int);
voidmain()
{
inta[]={5,6,7,8},i;
fun(a,4);
for(i=0;i
voidmain()
{
inti,j,max;
introw=0,column=0;
inta[3][3]={{1,2,3},{2,-3,4},{9,4,7}};
max=a[0][0];
for(i=0;imax)
{
max=a[i][j];
row=i+1;
column=j+1;
}
}
printf("max=%d,row=%d,column=%d\n",max,row,column);
}
(書中例題5.5,p123)
max=9,row=3,column=1
(3)
#include
intn=1;
voidfunc();
voidmain()
{
staticintx=5;
inty;
y=n;
printf("main:x=%d,y=%d,n=%d\n",x,y,n);
func();
printf("main:x=%d,y=%d,n=%d\n",x,y,n);
}
voidfunc()
{
staticintx=4;
inty=10;
x=x+2;
n=n+2;
y=y+n;
printf("func:x=%d,y=%d,n=%d\n",x,y,n);
}
main:x=5,y=1,n=1
func:x=6,y=13,n=3
main:x=5,y=1,n=3
(4)
#include
#include
structperson
{
charname[20];
intcount;
};
voidmain()
{
structpersonleader[3]={{"li",0},{"zhang",0},{"wang",0}};
charname[20],m,n;
for(m=1;m
#include
voidmain()
{
char*name[]={"capital","index","large","small"};
inta,b,n=4;
char*temp;
for(a=0;a0)
{
temp=name[a];
name[a]=name[b];
name[b]=temp;
}
}在此之前是書中的例題7.19for(a=0;a
#include
voidmain()
{
floata,b,c;
floatx1,x2;
floatx3,x4;
floatm;
printf("inputthenumbers:a,b,c");
scanf("%f%f%f",
if(a==0)
{
printf("theinputiserror!\n");
return;
}
m=b*b-4*a*c;
if(m>0)
{
x1=(-b+sqrt(m))/(2*a);
x2=(-b-sqrt(m))/(2*a);
printf("x1:%.2fx2:%.2f\n",x1,x2);
}
elseif(m==0)
{
x1=x2=(-b+sqrt(m))/(2*a);
printf("x1=x2=%.2f\n",x1);
}
else
{
x3=-b/(2*a);
x4=sqrt(m)/(2*a);
printf("x1=%.2f+%.2fi\n",x3,x4);
printf("x2=%.2f-%.2fi\n",x3,x4);
}
}
(2)編寫一個(gè)函數(shù),求s=a+aa+aaa++aaaaaaaaaa,其中a是一個(gè)數(shù)字,例如2+22+222+2222(此時(shí)n=4)。主函數(shù)a和n的輸入,調(diào)用所函數(shù)和輸出所求的累加和;編寫的函數(shù)完成計(jì)算。(9分)
注重:不得使用全局變量,注重程序結(jié)構(gòu)
(書中習(xí)題3:4。16)
#include
#include
longCal(longa,longn);
main()
{
longsn=0;
longa,n;
printf("pleaseinputan:");
scanf("%d%d",
sn=Cal(a,n);
printf("a+aa+aaa+...+aa...a=%ld\n\n",sn);
}
longintCal(longa,longn)
{
inti;
longsn=0,m=0;
for(i=0;i
#include
main()
{
chars[10][80];
chars2[80];
inti,j;
intnum=0;
printf("pleaseenter10string:\n");
for(i=0;i
#defineN5
structStudent
{
charname[20];
intnumber;
intsex;
floatscore[5];
floataver;
};
voidInput(structStudent*stu);
voidAverage(structStudent*stu,float*aver);
voidSort(structStudent*stu);
voidSearch(structStudent*stu,floatscore);
main()
{
structStudentstu[N];
floatscore=85.0;
floataver3;
Input(stu);
Sort(stu);
Average(stu,
printf("average3is%.2f\n",aver3);
Search(stu,score);
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024屆天津二十一中學(xué)中考數(shù)學(xué)最后一模試卷含解析
- 卵圓孔未閉的健康宣教
- 新生兒嘔血和便血的健康宣教
- 小兒偏身麻木的健康宣教
- 花都景點(diǎn)線路
- 新生兒流行性腹瀉的健康宣教
- 生物技術(shù)考研基因工程單選題100道及答案
- 2025供熱供應(yīng)合同范本
- 2025年張家界駕??荚嚳拓涍\(yùn)從業(yè)資格證考試題庫
- 地質(zhì)高級(jí)工程師證書驗(yàn)證流程
- 基金應(yīng)知應(yīng)會(huì)專項(xiàng)考試題庫(證券類190題)附有答案
- 節(jié)流式差壓流量計(jì)工作原理
- 精神科手衛(wèi)生與患者關(guān)懷
- 2024年江蘇省泰州市姜堰區(qū)中考二?;瘜W(xué)試題(無答案)
- 村辦公樓可行性研究報(bào)告
- MOOC 知識(shí)創(chuàng)新與學(xué)術(shù)規(guī)范-南京大學(xué) 中國大學(xué)慕課答案
- MOOC 企業(yè)文化與商業(yè)倫理-東北大學(xué) 中國大學(xué)慕課答案
- 高考物理二輪復(fù)習(xí)課件力學(xué)三大觀點(diǎn)在電磁感應(yīng)中的應(yīng)用
- (2024年)小學(xué)體育籃球規(guī)則課件
- 吳明珠人物介紹
- 2024年北京京能清潔能源電力股份有限公司招聘筆試參考題庫含答案解析
評(píng)論
0/150
提交評(píng)論