版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、第二章 y>>二4 0x0002一. 選擇題5. DD001111100011二判斷題1. 錯(cuò)2. 錯(cuò)3. 錯(cuò)4. 錯(cuò)三.填空題1. B 662. nl=%dnn2=%dn3. 0四計(jì)算1(1) x|y = 0x002f x'y = 0x0026 x&y = 0x0009; x+ y 二 0xffc6 x«=3 0x0068(1) 6501(4) - 161203(1) 0114814120127127 -295(1) 011(4)32五.程序分析題程序1b=20a=3600程序2第三章一.填空題=63. (1) scanf&c);(2) c-32
2、 更好的答案:c-('a'-'A')main () int a, b;printf (,zplease input a & b:");scanf ("%d%d", &a, &b);printf ("nmax is %dn,> (a>b)a:b);int max(int x,int y):main ()int a, b, c, max;printf (/'please input a & b & c:);scanf ("%d%d%d", &
3、;a, &b, &c);max=za>ba:b;max二c>maxc:max;printf (z,nmax is %dn,max);main ()int i=0,sum二0;while(i<=100)sum+二i;i+;b+二 3;+100=%dn, sum);printf("1+2+3+main ()int i;int a=10, b=-3;int c;printf (,%6d%6d, a, b)for(i=2;i10;i+)c=3*b+a;printf ("%6d", c);a=b;b=c;printfCW);main ()w
4、hile (1)printf (''please input a data(O: exit):");scanf&i);辻(i=0)break;if(i%2=0)printf ("the data %d is a even number n", i);elseprintf ("the data %d is a odd number i);ttinclude <>main ()int i;int a二&b二 1;int sum=0;for(i=0;i<10;i+)sum +二 a;a+=b;printf (z
5、,a%8db:%8dn", a, b);printf ("The Sum Of Is:%dn", sum); ftinclude <>main ()f loat x, y;printf("please input x:);scanf (“f", &x);if (x<else if (x<10)y=2*x-l;elsey=3*x-ll;printf("y=%fn", y); ftinclude <>main ()long a, i, b, al;while (1)printf (pl
6、ease input data(1-99999) :z,);scanf&a);printf ("a:%ldn", a);辻(a<=0|a>=100000)break;i=0;al=0;while(a!=0)b=a%10;printf("%8d", b);a/=10;i+;al二al*10+b;printf (z,n i :%Idal :%ldn", i, al);tiinclude <>include <>ttinclude <>main ()int a, b, i, k=0;random
7、ize ();a=random(1001);/*create a random data(0-1000)*/for(i=0;i<20;i+)printf(/'please guess a number:");scanf&b);辻(a>b)k+;printf (n%d:Smaller, guess again! n,z, k);else if (a<b)k+; printf (,zn%d:Bigger, guess again! n,z, k);elseprintf (/zn¥ou guess right, congraturation!);
8、printf ("AnYou have guessed %d times", k); break;if(k=20)printf (z,nsorry, you failed!");ttinclude <>main ()int a, b, c;int num;for(a二0;a<10;a+)for (b=0;b<10;b+)for(c=l;c<10;c+)num=a*100+b*10+c;if(num%3=0)&&(a=5b=5|,c=5)printf ("%8d", num);printf("
9、;nnn");tiinclude <>main ()int i;int a, b;printf("please input a,b:");scanf&a, &b);for(i=a<ba:b;i>0;i一一)if (a%i=0&&b%i=0) printf ("The max二%d", i); break;for(i=a>ba:b;i>0;i+)if(i%a=O&&i%b=O)printf ("nThe min=%d", i); break;t
10、tinclude <>main ()int a, k=0;printf("please input data:"); scanf (“%d: &a);wh訂e(a%2=0)a=a/2;k+;printf (,znthe number of factor (2) is %d,z, k); main ()long i, t二 1;long sum二0;for(i=l;i<=10;i+)t*=i;sum+二t;printf("%ld!=%ldn",i,t);printf (,sum:%ldn/,, sum);tiinclude <
11、;>void main ()int i,x=0;for(i=9;i>=l;i一一)x二2*(x+l);printf ("The first day x);ttinclude <>#define PImain ()float r, h;float v;printf("please input r, h:");scanf", &r, &h);v二3*PI*r*r*h;printf (”V=%. 2f", v);ttincludeOftincludeOmain ()long int sn=0;long int
12、m=0, t二0;int a, n, i ;printf("please input a n:");scanf (,%d%d,> &a, &n);for(i=0;i<n;i+)m二m*l0+a;sn+二m;printf (,za+aa+aaa+ +aa a=%ldnn,z, sn);ttinclude <>main ()int k;printf("please input k:);doif(k>=0&&k<=6)break;while (1);switch(k)case O:printf(Sund
13、ay. n);break;case 1: printf (z,Monday. n); break;case 2:printf ("Tuesday. n") ;break;case 3:printf("Wednesday n);break;case 4:printf("Thursdayn"):break;case 5:printf("Friday. n):break;case 6:printf(Saturday. n);break;ttinclude <>main ()int i;double x, a, b=l, sum=
14、l;printf(,zplease input x:);scanf ("%lf&x);a二 x;for(i=l;a/b>=le6;i+)sum二sum+a/b;a二a*x;b=(i+l)*b;printf ("'nsunrflf ", sum);include <>ttinclude <>main ()f loat a, xl, x2;printf("input a:");scanf ("%f", &a);xl=;wh訂e (1)x2=2*(xl+a/xl);辻(fabs
15、(x2-xl)<le5)break;xl二x2;printf (sqrt (a) =%f' x2);第四章寫(xiě)出下列程序輸出結(jié)果1 a=lno 1 a=Ono 1 a=lno 12.a=0b=0c 二0a=lb=0c=0a=2b=0c 二03.main:x=5, y二 1,n二 1 func :x=6, y二21, n二 11mainS, y二 1, n二 11func :x=8, y二31, n二21第五章6. (l)j+=2(2)ai<aj7. (l)si+ !=' 0'(2)si-l(同題4)i>= 0'&&si<二&
16、#39;9'12.0'(2) strl i-str2ittincludeOint fun ();int fun ()int a33, sum;int i, j;sum=0;/terror*/for(i=0;i<3;i+)for(j=0;j<3;j+)scanf&aij);/terror*/for(i=0;i<3;i+)sum二sum+aii;printf("sum二dn,sum);void main ()fun();ttinclude <>void main( void )float Num10;float Input, GetN
17、umll;int i, j;float 3=6;for(i=0; i<10; i+)Numi二 a;a=a+;Loopl: printf ("'Please input a Number (0-80) Input二"); scanf("%f", &Input);if(Input<0)|(Input>70)=l) goto Loopl;for(i=0; i<10; i+ )if (Input<Numi)goto Loop2;Loop2: for (j=0; j<i: j+ )GetNumLj=Numj;G
18、etNumj=Input;for(j=i; j<=10; j+,i+)GetNumj+1=Numi;for(j=0; j<U; j+ )printf ("%GetNumj); ftincludettincludemain ()int al, a2, a3, a4, a5, a6, a7, aS, a9;int a3;int i;£or(;)for (i=0;i<3;i+)ai=rand () %3;(al!=a2)/*getintothreewhile(a0!=al) && (a0!=a2)three different numbers 0
19、, 1, 2*/al二a0+l;/*divide19groups,al'a3, a4a6, a7a9*/a2=al+l;a3 二a +1;a4=al+3;a5=a2+3;a6=a3+3;a7二al+6;a8=a2+6;a9=a3+6;/* make sure thateach line and each row is made up withthree members in different group */'/* such as:a9 al a5a2 a6 a7a4 aS a3 */if(al+a5+a9) 二二(a2+a6+a7)&&(al+a5+a9)二
20、二(a3+a4+a8)&& (al+a6+a8)二二(a5+a7+a3) && (al+a5+a9)二二(a2+a4+a9)printf (“d %d %dn%d %d %dn%d %d %dn,z, a9, al, a5, a2, a6, a7, a4 ,aS, a3);return;ftinclude <> void main(void)char input 1100J, input2100, input3100J;int i, Eng二0, eng=0, num二0, blank=0, other二0;printf("Input 3
21、rows of character, each row don't exceed 80 characters: n,z);gets(inputl);printf (z,The second row: nz,);gets(input2);printf ("The third row:n");gets(input3);/*test the first row*/for(i=0; i<100; i+)if (inputl i=,0')goto Loopl;else if (' A'二inputl i)&&(inputli<
22、;=' Z' )=1)Eng+;else if (' a <=inputl i)&&(inputl iz)=1)eng+;else if (' O' <=inputli)&&(input 1 i<=,9" )=1)num+;else if(inputli=32)blank+;else other+;/*test the second row*/Loopl: for(i=0; i<100; i+)if(input2i二二'0')goto Loop2;else if ('
23、; A' <=input2i)&&(input2i<=,Z,)=1)Eng+;else if (' a <=input2i)&&(input2i<=,z' )=1)eng+;else if (' O'二input2 i)&&(input2 i<=' 9' )=1)num+;else if(input2i=32)blank+;else other+;/*test the third row*/Loop2: for(i=0; i<100; i+)if(inpu
24、t3i二二'0')goto Loop3;else if (' A' <=input3i)&&(input3i<=,Z,)=1)Eng+;else if (' a <=input3 i)&&(input3i <=,z' )=1)eng+;else if (' O' <=input3i)&&(input3i<=' 9' )=1)num+;else if (input3i二二32)blank+;else other+;Loop3:prin
25、tf("Upper english character:%dnLower englishcharacter:%dnNumber:%dnBlank:%dnOthercharacte:rs:%dn", Eng, eng, num, blank, other);ftinclude <> void main(void)char str1 80, str240;int i, j, k;/*Input two string*/printf("Please input the first stringn str1二“); gets (strl);printf(&qu
26、ot;Please input the second stringn str2="); gets (str2);/*Get the end of strl*/for(i=0; i<80; i+)if (strl i=,0')break;/*Copy str2 to strl*/for (j=i, k=0; str2 k != 0' ; k+, j+)strl j二str2k;strli+k= 0J ;puts(strl);ftinclude <>struct studentchar name20;int score;stu5, stul;void m
27、ain(void) int i, j ;printf("Input student's score and name(5), seperate using the character of ' , ':n");for(i=0; i<5; i+)scanf%sz,, &stui score, &stu i name);/*sorting*/for(i=0; i<5; i+)for(j=0; j<4-i; j+)if (stuj score>stuLj+1 score)stul二stuj ;stuj二stuj+l
28、;stuj+1二stul;printf (z,After sot red, score and name:n);for (j=0;j<=2;j+)printf (%d, %sn,z, stuLi score, stui name ttincludeOmain () int aL3 3, i, j, m, n, o, p;printf("Please input a 3*3 shuzu:n");for (i=0;i<=2;i+)for (j=0;j<=2;j+)scanf ("%d", &ai j);for (i=0;i<=
29、2;i+) m二(ai 0ai 1) ai 0 :ai 1;n二(m>ai2) m: aLi2;o=(a0 j<al j) a0 j :al j;p=(o<a2 j) o: a2j;if (n=p)printf (,z Andi an is %dn", p);elseprintf ("There is no andian. n");ttinclude <>void main(void) int a4 3, b3 4, i, j;for(i=0; i<4; i+) for(j=0; j<3; j+)scanf ("
30、%d", &ai j);for(i=0; i<4; i+)printf("n");for(j=0; j<3; j+)printf ("%5d ", aij);for(i=0; i<4; i+)for(j=0; j<3; j+) bji二 aij;printf(n);for(i=0; i<3; i+)printf("n");for(j=0; j<4; j+)printf (*%5d ", bij);tiinclude <>ttincludeOvoid main(
31、void) char str 6;int i, j=0, m=0, n=0;gets (str);while(strj!二'0')j+;for(i=jl;i>=0;i-)m=(str i-5 O') *(pow(8, j-il);n+二m;printf ("shi jinzhi %d/,, n): tiinclude <>void main(void)char input1lOOj;int i, num二0, blank二0;printf ("Please input a row character: n,z);gets(input
32、l);/*test the first row*/for(i=0; i<100; i+)if (inputl i= 0')goto Loop;else if (' A' <=inputl i)&&(inputli<=,Z,)=1) num+;else if (' a <=inputl i)&&(input 1 i二'z,)=1) num+;else if (inputli二二32)blank+;Loop: printf (''Character:%dnBlank:%dn",
33、 num, blank);第六章一、選擇題:P中記錄的是a的地址,*戸訪問(wèn)地址a的值:指針數(shù)組:指針可以進(jìn)行是否相等判斷,空指針可以進(jìn)行指針變量初始化,指 針可以偏移;、D: a5不存在,若*&a4則正確;C,D正確;二、填空題1. *(p+3)2222 cdefgbcdefgabcdefg73. 6385三程序分析題1. P = s0;錯(cuò)誤,應(yīng)改為:p = s;或 p 二 &s0;2. int x , *p;錯(cuò)誤,應(yīng)改為:double x, *p;3. *p二x ;錯(cuò)誤,應(yīng)改為:p二&x ;4. 聲明順序錯(cuò)誤;應(yīng)該改為:void main(void)int a;int
34、 *p 二 &a;a = 10;printf( “dn” , *p);ttinclude <>ttinclude <>main ()char ch25 = "6937", 8254", *p2;int i, j, s=0;for(i=0;i<2;i+)pi = chi;for(i=0;i<2;i+)for(j=0;pi Ej>,0' ; j+=2)=10*s + pij - 'O'ttinclude <>ttinclude <>main ()int count 二 0
35、;char strl 100, str2100;char *pl,*p2;printf (,zplease enter string 1:");gets(strl);printf("please enter string 2:");gets(str2);printf ("strl:%snz,, strl);printf("str2str2);pl = strl;p2 = str2;while(*pl!2 0&&*p2!= 0)if (*p 1 +*p2+)count+;printf ("count:%dn,z, cou
36、nt);ttinclude <>ttinclude <> main ()int i, j, k;int a3;int temp;printf("please enter array a3:");scanf (,%d%d%d,/, &a0, &al, &a2);for(i=0;i<2;i+)k = i;for(j= i+l;j3;j+)if (aj<ai)k = j;temp 二 ai;ai = ak;ak二 temp;for(i=0;i<3;i+)printf ("%dt", ai);pr
37、intf Cn");include <>ftinclude <> ftdefine N 100main ()char slN, s2N,*p;int m;printf("please enter string】:");gets(sl);P = si;printf("enter m:);scanf&m);strcpy (s2, p+m);printf("string2:%sn", s2);ttinclude <>ttinclude <>main ()char s100=/iuiui
38、012asdd90k890y098kkkkl234,,*p;char data100100=0;int count=0;int i;P 二 S;/*printf("please enter a string:");gets(p);*/printf("ssssss);while (*p!二'0')i 二0;while (*p>= 0'&&*p<=' 9')datacounti = *p;i+;P+;if(i!=0)count+;P+;printf("count:%dn", cou
39、nt);for (i=0;i<count;i+)printf (,%sn,> datai);ttinclude <>define SIZE 4main ()int data SIZE SIZE, i, j,d;int max, m=0, n=0;for(i=0;i<SIZE;i+)for(j=0;j<SIZE;j+)scanf&dataij);for(i=0;i<SIZE;i+)for(j=i+l;j<SIZE;j+)d = dataij;dataij = dataji;dataj i = d;max = data00;for(i=0;i
40、<SIZE;i+)printf ("n");for(j=0;j<SIZE;j+)printf(”4d", dataij);if(dataiLjl >=max)max = dataij;m = i;n = j;printf("nmax:%4dm:%d n:%dn", max, m, n);ttinclude <>tiinclude <>main ()char *p = "test",“capital", "index", "large"
41、, "small"char *pstr 二 p;int a, b, n = 5;char *temp;for (a=0;a<n-l;a+)for (b二a+1;b<n;b+)if (strcmp (pstr La, pstr -b) >0)temp 二 pstra;pstra二 pstr b;pstrb二 temp;for(a二0;a<n;a+)printf ("%sn", pstr a);ttinclude <>ttinclude <>main ()char slIOO, temp;char *p 二 s
42、;int i,length;printf("please enter a string: “);gets(s);while(*p+!二0');length 二 p - s T;printf("string length:%dn", length);for(i=0;i<length/2;i+)temp 二 si;s i二 s length-iT;slength-i-1二 temp;printf("%sn",s);第七章一,選擇題二. 程序填空題1.(1) ak(2) ak(3) ak2.(1) ai(2) j(3) i+1 或 6三
43、. 改錯(cuò)題1.ttincludeOftincludeOvoid swap (char *, char *) ;/*此處有錯(cuò)誤,函數(shù)聲明時(shí)要加分號(hào)*/main ()char a 80, b 80, c 80;scanf("%s%s%s,a,b,c); /*此處有錯(cuò)誤,a, b, c分別為數(shù)組a80,b8,c80的首地址*/if (strcmp(a, b)>0) swap (a, b) ;/*此處有錯(cuò)誤,字符串比較應(yīng)該使用strcmp函數(shù)*/if (strcmp (b, c) >0) swap (b, c) ;/*此處有錯(cuò)誤,原因同上*/if (strcmp(a, b)>
44、;0) swap (a, b) :/*原算法不能實(shí)現(xiàn)排序,需要添加此語(yǔ)句*/printf (”sn%sn%sn", a, b, c);<>ttinclude <>void swap(char *pstrl, char *pstr2)char pL80:strcpy (p,pstrl);strcpy (pstri, pstr2);strcpy (pstr2, p);main ()char a80="ccc", b80="bbb", c 80 ="aaa"/* scanf ("%s%s%s&qu
45、ot;, a, b, c) ;*/if(strcmp(a, b)>0)swap(a,b);if(strcmp(b, c)>0)swap (b,c);if(strcmp(a, b)>0)swap(a,b);printf(”sn%sn%snnn", a, b,c);<>int SquSum(int, int);main ()int a, b;int c;printf ("enter 2 integer:z/):scanf (,%d%d,> &a, &b);c 二 SquSum(a, b);printf (,a=%d b :%d
46、a2+b2=%dn", a, b, c);int SquSum(int x, int y)int z;z 二 x*x+y*y;return z;<>int GongYueShu(int, int);int GongBeiShu(int, int);main ()int a, b;int gbs, gys;printf ("enter 2 integer:zz):scanf ("%d%d", &a, &b);gys 二 GongYueShu(a, b);gbs 二 GongBeiShu(a, b);if (gys<0)pr
47、intf ("There has not gong yue shu!n);elseprintf (/'max gong yue shu:%dn,z, gys);printf ("min gong bei shu:%dnz,, gbs);int GongYueShu(int x, int y)int i,gys-l, min;min = x;if (x>y)min = y;for(i=2;i<=min;i+)if(x%i=0)&&(y%i=0) gys = i;return gys;int GongBeiShu(int x, int y)i
48、nt i, gbs, max;max = x;辻(y>x)max = y;for (i二max;i<=x*y;i+)if(i%x=0)&&(i%y=0)gbs = i; break;return gbs;<>tiinclude <> void DeleteCh(charmain ()string:,z);char:);char str80, ch;printf("please agets (str);printf("please ascanf&ch);Delete_Ch(str,ch)printf (,%snn,
49、str);void Delete_Ch(char *p,char ch)while(*p)if (*p二二ch)strcpy (p, p+1);elsep+;<>int Is_ShuShu(int);/* return 0:shushureturn -1:no shushu*/main ()int a,ret;printf (z,pls enter a integer :,z);scanf(“d", &a);ret 二 Is_ShuShu(a);if(ret=O)printf("%d is a shushu!n", a); elseprintf("%d is not a shushu'n", a)
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝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ù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 工廠車(chē)間現(xiàn)場(chǎng)5培訓(xùn)
- 核安全風(fēng)險(xiǎn)辨識(shí)
- 數(shù)控車(chē)削加工技術(shù) 課件 項(xiàng)目七 端面切削工藝及編程
- (提升卷)第一單元 圓和扇形(單元測(cè)試)數(shù)學(xué)六年級(jí)上冊(cè)單元速記巧練系列(冀教版)學(xué)生版
- 福建省泉州市南安市2024-2025學(xué)年四年級(jí)上學(xué)期期中考試數(shù)學(xué)試題 - 副本
- T-XYTX 002-2024 黃桃標(biāo)準(zhǔn)化生產(chǎn)與基地建設(shè)
- 河北省衡水市武強(qiáng)中學(xué)2024-2025學(xué)年高三年級(jí)上學(xué)期期中考試英語(yǔ)試題 含解析
- 高中語(yǔ)文第3單元文藝評(píng)論和隨筆第9課說(shuō)“木葉”課件新人教版必修
- 棄土場(chǎng)施工方案
- Windows Server網(wǎng)絡(luò)管理項(xiàng)目教程(Windows Server 2022)(微課版)10.5 拓展案例2 NAT端口映射
- 牙合-學(xué)講義一章二章課件
- 對(duì)監(jiān)獄心理矯治工作存在的問(wèn)題與對(duì)策的幾點(diǎn)思考
- 小學(xué)英語(yǔ)繪本閱讀課-My-gradma-goes-to-school精品公開(kāi)教學(xué)設(shè)計(jì)教案
- 中職《機(jī)械基礎(chǔ)》(二版)模塊六--常用機(jī)構(gòu)云天課件
- 順豐物流員工手冊(cè)
- 燃煤發(fā)電廠風(fēng)險(xiǎn)源辨識(shí)及管理控制措施
- 一年級(jí)拼音每日拼讀練習(xí)
- 山西普通高中學(xué)生學(xué)籍登記表完整優(yōu)秀版
- 七年級(jí)上冊(cè)生命、生態(tài)、安全教案 全冊(cè)
- 陜西_介紹ppt
- 下穿有軌電車(chē)專項(xiàng)監(jiān)測(cè)方案
評(píng)論
0/150
提交評(píng)論