2012級(jí)信息學(xué)院C語(yǔ)言試卷答案及評(píng)分規(guī)則_第1頁(yè)
2012級(jí)信息學(xué)院C語(yǔ)言試卷答案及評(píng)分規(guī)則_第2頁(yè)
2012級(jí)信息學(xué)院C語(yǔ)言試卷答案及評(píng)分規(guī)則_第3頁(yè)
2012級(jí)信息學(xué)院C語(yǔ)言試卷答案及評(píng)分規(guī)則_第4頁(yè)
2012級(jí)信息學(xué)院C語(yǔ)言試卷答案及評(píng)分規(guī)則_第5頁(yè)
已閱讀5頁(yè),還剩12頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上2012級(jí)信息學(xué)院C語(yǔ)言程序設(shè)計(jì)試卷(閉卷)1、 判斷下列語(yǔ)句或程序的對(duì)錯(cuò)。(“×”表示錯(cuò),“”表示對(duì))(10分) /評(píng)分:每小題1分( 1) char ch=55; ( × )( 2 ) unsigned int a=b=c=5; ( × ) ( 3) int a=2,*p; p=&a; printf(”%d”, *&a); ( ) (4) int a55, (*p)5; ( × ) p=&a00;(5) char a=a,c; ( ) c=a+;(6) int n; scanf(”%d”,&n

2、); ( × ) int an; (7) int a10,*p; ( ) p=a+2;(8) int a,b; ( × ) scanf(”%d,%f”,a,b);(9) float a=1,*b=&a,*c=&b; ( × )(10) char str=”World”; ( ) printf(”%c”,*(str+2);二、計(jì)算下列表達(dá)式的值(10分) /評(píng)分:每小題2分 設(shè) int x=3,y=-4,z=4; float k=3.5;(1) x+ - y+ +z ( 12 )(2) y>z|z>2&&x+ ( 1 )(

3、3) x|z&xz ( 7 )(4) x-y+!z-1&&x+y/2 ( 1 )(5) y+(x/3*(int)(x+k)/2)%4 ( -1 )三、改錯(cuò),根據(jù)題意改正下列程序的錯(cuò)誤和漏掉的部分(10分)(1)輸入球體半徑r,求其體積.#include “stdio.h”; #include “stdio.h” 0.5分define pi=3.; #define pi 3. 0.5分float volume(int r); float volume(float r); 1分void mian() void main() 0.5分 float r,v; scanf(“%d

4、”, r); scanf(“%f”, &r); 0.5分 v= volume(r); printf(“%d”,v); printf(“%f”,v); 0.5分float volume(int r); float volume(float r) 0.5分 v=4/3*pi*r*r*r; v=4.0/3*pi*r*r*r; 1分 return v;(2)利用指針數(shù)組對(duì)字符數(shù)組中的5個(gè)姓名字符串排序,字符數(shù)組內(nèi)容不變。.#include <stdio.h> #include <stdio.h> 0.5分 #include <string.h> 0.5分 v

5、oid main() char name520; char* p5; int i; int i,j; 0.5分 char temp20; char *temp; 0.5分 for(i=0;i<=5;i+) for(i=0;i<5;i+) 0.5分 gets(name+i); p=namei; pi=name+i; 或pi=namei 0.5分for(i=0;i<5;i+) for(j=0;j<5;j+) for(j=i+1;j<5;j+) 0.5分 if(pi>pj) if(strcmp(pi,pj)>0) 或if(strcmp(pi,pj)<0

6、) 0.5分 temp=pi;pi=pj;pj=pi;for(i=0;i<5;i+) printf(“%c”,pi); printf(“%s”,pi); 1分4、 程序填空(10分) /評(píng)分:每空1分(1)給出年月日,計(jì)算出該日是該年的第幾天。#include <stdio.h> void main( )   int year, month, day, days, i, d;  printf(“請(qǐng)輸入年,月,日:”); scanf(“%d%d%d”,

7、0;&year, &month, &day);  days=0;  for( i=1;  i<month ; i+)    switch (  i )    case 1:  case 3:  case 5:  case 7:  case 8:  case 10:  c

8、ase 12: d=31;  break ;   case 4:  case 6:   case 9:case 11:  d=30; break;  case 2:  if (year%4=0&&year %100 !=0 | year%400=0)  d=29;  else  d=28;  break;   days+=

9、d ;     printf(“%d年%d月%d日是該年的第%d天n”,year, month ,day,  days+day );   (2)將一個(gè)指字符串的正序和反序進(jìn)行連接,形成一個(gè)新串放在另一個(gè)字符數(shù)組 中。例如:當(dāng)字符串為"ABCD"時(shí),則新字符數(shù)組的內(nèi)容應(yīng)為"ABCDDCBA"。#include <stdio.h> #include <string.h>  void fun (char

10、60;*s, char *t);void main()    char  S100, T100;  printf("nPlease enter string S:");  scanf("%s", S );  fun(S, T);  printf("nThe result is: %sn", T);  void 

11、;fun (char *s, char *t)   int  i, d;   d =  strlen(s)    for (i = 0; i<d;   i+ )  ti = si;  for (i = 0; i<d; i+)  ti+d   = sd-1-i;  ti

12、+d =0   ;   五、寫程序輸出結(jié)果(25分) /評(píng)分:每小題5分,根據(jù)情況酌情扣分(1)#include <stdio.h>int a = 1;void func()static int x=1;int y=2;x = x+1;a = a+2;y = y+a;printf("func: x=%d, y=%d, a=%dn", x, y, a);void main()static int x = 2;int y;y=a;printf("main: x=%d, y=%d, a=%dn", x, y, a);f

13、unc();printf("main:x=%d,y=%d, a=%dn" ,x, y ,a);func(); int a ; a= x+y; printf("main:x=%d,y=%d, a=%dn" ,x, y ,a);答案:main: x=2,y=1,a=1func: x=2,y=5,a=3main:x=2,y=1,a=3func:x=3,y=7,a=5main:x=2,y=1,a=3(2)#include "stdio.h"#define M 10void main( ) int aM+1=10,20,30,40,50,60,

14、70,80,90,100; int i,n,*p,*q; n = 45; aM=n; for(p=a,i=0;i<=M;i+) if(n<=*(p+i) p=p+i; break; for(q=a+M-1; q>=p; q-) *(q+1)=*q; *p=n; for(p=a,i=0;i<M+1;i+) printf("%d,",pi); 答案:10,20,30,40,45,50,60,70,80,90,100,(3)#include <string.h>#include <stdio.h>void main()char ch

15、;unsigned int i,j,bit,dit,n;long int a20; char *str = "a123x456_789"for (i=0,j=0,a0=0,bit=1,dit=0; i<strlen(str) ;i+) ch=*(str+i); if(ch>='0'&&ch<='9') aj*=bit; aj+=(ch-48); bit=10; dit=1;n=j; else if (dit=1) j+; aj=0 ; dit=0; bit=1; for (i=0;i<=n;i+) pr

16、intf("a%d=%d,",i,*(a+i); 答案:a 0=123,a1=456,a2=789, (4)#include<stdio.h>struct Key char *keyword; int keyno;void main( ) struct Key kd3 = "are",123,"your",456, "my", 789; struct Key *p; int a; char *str; p = kd;str = p->keyword; printf("str = %sn&

17、quot;,str); a = p+->keyno; printf("a = %dn",a); a = p->keyno; printf("a = %dn",a); 答案:str=area=123a=456(5)#include <stdio.h>#include <string.h>struct person char name20; int count;void main() struct person leader3="liu",80,"zhang",30,"wa

18、ng",100; char name20 = "wang",m,n; for(n=0;n<3;n+) if(!strcmp(name,) m = leadern.count; break; printf("count=%dn",m); for(n=0;n<3;n+) printf("%s:%dn",,leadern.count);答案:count =100liu:80zhang:30wang:1006、 編寫程序(35分)(1)已知四位數(shù)a2b3能被23整除,編程求

19、此四位數(shù)。(9分)#include<stdio.h> /頭文件及主函數(shù)框架1分void main() int a,b; /變量定義1分 int num; for(a=1;a<=9;a+) /循環(huán)結(jié)構(gòu)3分 for( b=0;b<=9;b+) num = 1000*a+200+10*b+3; /數(shù)據(jù)合成2分 if(num%23=0) /整除條件1分 printf(“得到滿足條件的四位數(shù)之一是:%dn”,num); /輸出1分(2)一球從100米高度自由落下,每次落地后反彈調(diào)回原高度的一半,再落下;求它在第10次落地時(shí),共經(jīng)過多少米?第10次反彈多高?(9分)#include

20、<stdio.h> /頭文件及主函數(shù)框架1分void main( ) float sn=100.0; /變量定義1分 float hn=sn/2; int n; for( n=1;n<10;n+) /循環(huán)語(yǔ)句2分 sn=sn+2*hn; /結(jié)合算法2分 hn=hn/2; /遞推求求后項(xiàng)2分 printf(“第10次落地時(shí)共經(jīng)過%f米.n”,sn); /輸出1分 printf(“第10次反彈%f米.n”,hn);(3) 一個(gè)公司,有若干名員工,每名員工有姓名,性別,工齡,工資等信息。編程輸入并建立員工檔案信息,并要求輸出工齡大于10年,工資少于3000元的所有男員工信息。(輸入

21、和輸出過程用不同函數(shù)實(shí)現(xiàn))(9分) #include <stdio.h> #define N 3 struct Employee char name20; char sex; int work_year; int wage; ; /結(jié)構(gòu)定義1分 void input_data(struct Employee *person); void output_data(struct Employee *person); /函數(shù)聲明1分 void main() /函數(shù)及函數(shù)調(diào)用3分 struct Employee personN; input_data(person); output_dat

22、a(person); void input_data(struct Employee *person) /函數(shù)定義2分 for(int i=0;i<N;i+) printf("Name?"); gets(); printf("SEX?"); personi.sex=getchar(); printf("work_year?"); scanf("%d",&personi.work_year); printf("wage?"); scanf("%d&q

23、uot;,&personi.wage); getchar(); void output_data(struct Employee *person)/函數(shù)定義2分 for(int i=0;i<N;i+) if(personi.sex='0'&&personi.work_year>10&&personi.wage<3000) printf("%st%ct%dt%dn",,personi.sex,personi.work_year,personi.wage); (4)輸入一行包含若干

24、單詞的字符串,單詞之間用空格分開,要求按單詞長(zhǎng)短從小到大的次序排序后形成新的字符串輸出。(假定字符串中單詞個(gè)數(shù)不超過10個(gè),字符串輸入并形成單詞序列,單詞排序,形成新串并輸出要求用不同的函數(shù)實(shí)現(xiàn))(8分) #include <stdio.h> #include <conio.h> #include <string.h> int input_str(char *str,char (*word_str)100); void sortstr(char (*word_str)100,int num); void output_str(char (*word_str)100,int num);/頭文件函數(shù)聲明1分 void main() /主函數(shù)及函數(shù)調(diào)用2分 char str100;/字符串 char word_str10100;/存放單詞的二維數(shù)組 int num=input_str(str,word_str); sortstr(word_str,num); outpu

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝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)論