c Programming Part1 v3.5 2

12
© By Q 3D/2 (CE KMITL 49)(RSix) http://aikkew.kmi.tl/c [email protected] 1 แบบฝึกความเข้าใจารเขียนโปรแกรมด้วยภาษา C Last update : 8 กรกฎาคม (Version 3.5) แบบฝึกความเข้าใจการเขียนโปรแกรมด้วยภาษา C By Aikkew Q Sang หัวข้อ 1. ความรู้พื .นฐานเกี0ยวกับคอมพิวเตอร์ 2. ภาษาซี การเขียนโปรแกรมเบื .องต้น และคําสั 0งแสดงผล 3. ชนิดข้อมูลในภาษาซี คําสั 0งรับข้อมูล และการคํานวณ 4. ผังงาน และการเขียนโปรแกรมกําหนดเงื0อนไข 5. การเขียนโปรแกรมแบบวนซํ . คําชี .แจง 1. โปรแกรมในแบบฝึกหัดนี .ได้ประกาศ preprocessor directive ที0ถูกต้องครบถ้วนเรียบร้อยแล้ว 2. กําหนดให้ตัวอักษรบนหน้าจอแสดงผล (Output) กว้าง 80 ตัวอักษรและสูง 25 บรรทัด 3. หากเอกสารชุดนี .มีความผิดพลาด ประการใด ผู้จัดทําขออภัยมา ณ ที0นี . และโปรดแจ้งให้ทราบเพื0อที0 ผู้จัดทําจะได้นําข้อผิดพลาดไปแก้ไขต่อไป Special thanks CE KMITL (Computer Engineering KMITL) (http://www.ce.kmitl.ac.th) สําหรับเอกสารประกอบการเรียนและแหล่งความรู้ต่างๆ CSAG (Computer System Administrator Group) (http://csag.kmi.tl) สําหรับการสนับสนุนอุปกรณ์ต่อการทําแบบฝึกนี .ขึ .นมา WebServ.KMITL (http://webserv.kmitl.ac.th) สําหรับพื .นที0 Hosting ให้ใช้งาน KMI.TL (http://kmi.tl) สําหรับ URL ที0สะดวกและจําง่าย

description

c

Transcript of c Programming Part1 v3.5 2

Page 1: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

1 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C

By Aikkew Q Sang

หวขอ

1. ความรพ.นฐานเก0ยวกบคอมพวเตอร

2. ภาษาซ การเขยนโปรแกรมเบ.องตน และคาส0งแสดงผล

3. ชนดขอมลในภาษาซ คาส0งรบขอมล และการคานวณ

4. ผงงาน และการเขยนโปรแกรมกาหนดเง0อนไข

5. การเขยนโปรแกรมแบบวนซ. า

คาช.แจง

1. โปรแกรมในแบบฝกหดน.ไดประกาศ preprocessor directive ท0ถกตองครบถวนเรยบรอยแลว

2. กาหนดใหตวอกษรบนหนาจอแสดงผล (Output) กวาง 80 ตวอกษรและสง 25 บรรทด

3. หากเอกสารชดน. มความผดพลาด ประการใด ผจดทาขออภยมา ณ ท0น. และโปรดแจงใหทราบเพ0อท0

ผจดทาจะไดนาขอผดพลาดไปแกไขตอไป

Special thanks

CE KMITL (Computer Engineering KMITL) (http://www.ce.kmitl.ac.th)

สาหรบเอกสารประกอบการเรยนและแหลงความรตางๆ

CSAG (Computer System Administrator Group) (http://csag.kmi.tl)

สาหรบการสนบสนนอปกรณตอการทาแบบฝกน. ข.นมา

WebServ.KMITL (http://webserv.kmitl.ac.th)

สาหรบพ.นท0 Hosting ใหใชงาน

KMI.TL (http://kmi.tl)

สาหรบ URL ท0สะดวกและจางาย

Page 2: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

2 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

1. อปกรณใดจดอยในประเภทอนพท (Input) a) หนาจอ b) เคร0องพมพ c) คยบอรด c) ลาโพง e) เคร0องฉายภาพ

2. ขอใดตอไปน. ถอวาเปน Hardware a) Programmer b) Windows 8 c) Google Chrome d) Driver e) Printer

3. ยนกซ จดวาเปนซอฟแวรประเภทใด a) ซอฟแวรระบบ b) ซอฟแวรใชงานเฉพาะ c) ซอฟแวรประยกต d) ซอฟแวรซ.อขาย e) ไมมขอใดถก

4. ขอใดคอเลขฐาน 2 ของ 5010

a) 110001 b) 110010 c) 110110 d) 100011 e) 101011

5. ขอใดคอเลขฐาน 16 ของ 94610

a) 3122 b) 3D2 c) 03B2 d) 1661 e) A051

6. ขอใดคอเลขฐาน 8 ของ AF16

a) 175 b) 184 c) 219 d) 236 e) 257

7. ขอใดคอเลขฐาน 16 ของ 17228

a) 0AA b) 1B8 c) 299 d) 3D2 e) 0F1

8. คาของขอใดในฐาน 10 มคามากท0สด

a) 111111B b) 1000101B c) (104)8 d) 55 e) 3CH

9. ขอใดเรยงจากมากไปนอยไดถกตอง a) 1010012 338 2816

b) 1010012 2816 338

c) 338 1010012 2816

d) 338 2816 1010012

e) 2816 1010012 338

10. จากขอความตอไปน. มก0ขอความท0กลาวถกตอง 2D16 มากกวา 308 1001102 นอยกวา 458 1000002 เทากบ 3210 1001000102 ไมเทากบ 12316 a) 0 b) 1 c) 2 d) 3 e) 4

11. ขอใดคอ 1’s Complement และ 2’s Complement ของ 101102 (ตามลาดบ) a) 010012 , 010102 b) 101112 , 010012 c) 010102 , 010012 d) 101102 , 010102 e) 010012 , 010002

12. 1 ไบท = ก0บท 1 MB = ก0ไบท (ตอบตามลาดบ) a) 4,210 b) 8,210

c) 4,210x210 d) 8,210x210

e) ไมมขอใดถก

13. จากรหส ASCII คาท0เปนตวเลขฐานสบของตวอกษร A,a,0 คอขอใดตามลาดบ a) 65,97,48 b) 64,97,0 c) 65,97,0 d) 65,96 ,48 e) 66,96,46

Page 3: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

3 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

14. ขอใดกลาวไมถกตองเก0ยวกบภาษา C a) เปนภาษาโครงสราง จดวาเปนภาษาระดบสง b) ใชเคร0องหมาย { } เปนการกาหนดขอบเขตของ

คาส0งยอยๆหลายๆคาส0ง c) จะใชเคร0องหมาย ; เปนจดส.นสดคาส0ง d) ตวอกษรใหญหรอเลก มผลตางกน e) สามารถรนโปรแกรมท0เขยนน.นไดเลย

15. ขอใดกลาวไมถกตองกบการเขยน #include<math.h> a) จดอยในสวนของ Header Program b) เปนการประกาศตวแปรคณตศาสตรชนด Global c) จดเปนสวนของ Preprocessor Directive d) เปนการดงคาส0งจากไฟล math.h ท0อยใน Include

Directory e) เรยกไฟล math.h เพ0อทาใหสามารถใชคาส0ง

เก0ยวกบคณตศาสตรได 16. ขอใดคอผลลพธเม0อจบโปรแกรม

printf("Hello\,World\\!"); a) Hello\,World\\! b) Hello,World! c) Hello,World\! d) Hello\,World\! e) Hello,World\

17. ขอใดคอผลลพธเม0อจบโปรแกรม

printf(""^-^""); a) Compile Error b) Runtime Error c) "^-^" d) ^-^ e) 0

18. ขอใดคอผลลพธเม0อจบโปรแกรม

printf("CE\"\0@\nKMITL");

a) CE"0@ b) CE" @ KMITL KMITL c) CE"\0@ d) CE" KMITL e) ไมมขอใดถก

19. เม0อจบโปรแกรม ผลลพธท0ออกมามชองวางก0ตว กอนถงคาวา END printf("\tABCDEFG\t\tEND");

a) 7 b) 16 c) 17 d) 18 e) 24

20. ขอใดคอผลลพธเม0อจบโปรแกรม printf("5+6=%d",11);

a) 11 b) 5+6=11 c) 11=11 d) 5+6=%d e) เกด Compile Error

21. ขอใดคอผลลพธเม0อจบโปรแกรม printf("%d",'7'-7);

a) 48 b) 32 c) 16 d) 0 e) เกด Compile Error

22. ขอใดคอผลลพธเม0อจบโปรแกรม printf("%f",3.9);

a) 3 b) 3.9 c) 3.90 d) 3.900000 e) ไมมขอใดถก

23. ขอใดคอผลลพธเม0อจบโปรแกรม printf("%c%d",65,66);

a) A66 b) 66A c) 6566 d) %c%d e) ไมมขอใดถก

24. ขอใดคอผลลพธเม0อจบโปรแกรม printf("Q=%4d",'Q');

a)

b)

c)

d)

e)

Q = 8 1

Q = 8 1

Q = 8 1

Q = 8 1

Q = 8 1

Page 4: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

4 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

25. ขอใดคอผลลพธเม0อจบโปรแกรม printf("%-3.2s%2.1s#","0101101","0101101"); a)

b)

c)

d)

e)

26. การเขยน Comment แบบใด ไมเกดการ Error a) \\*\\//*/ b) //\//*/\/ c) */\/*//\\/* d) /\///\\\*// e) \*\\/*/\\*/

27. ตวแปร Integer ขนาด 2 bytes เกบตวเลขในชวงใดได a) -32767 ถง 32768 b) -127 ถง 128 c) -32768 ถง 32767 d) -128 ถง 127 e) -32768 ถง 32768

28. ถาตองการเกบคาตวเลขทศนยมระหวางศนยถงหกลาน ควรประกาศตวแปรชนดใดจงจะเหมาะสมท�สด a) unsigned int b) unsigned float c) int d) float e) double

29. การประกาศตวแปรแบบใดถกตองท�สด

a)

b)

c)

d)

e)

30. ช0อตวแปรใดตอไปน.สามารถประกาศได

a)

b)

c)

d)

e)

31. ขอใดคอผลลพธเม0อจบโปรแกรม float q=123.287; printf("\\%.2f",q); a) 123.2 b) 123.28 c) 123.29 d) 124.287 e) ไมมขอใดถก

32. ขอใดคอผลลพธเม0อจบโปรแกรม char str[]={"Jump"}; printf("%c%s%s",str[1],str,"str"); a) uJump b) JJump c) uJumpJump d) uJumpstr e) เกด Compile Error

33. รปแบบการเขยน scanf ในขอใดถกตอง a) scanf("%f %f",&grade,gpa); b) scanf("%d",age); c) scanf("%c",&char); d) scanf("%s",&name); e) scanf("%[^\n]",subject);

34. ขอใดคอผลลพธเม0อจบโปรแกรม int card=1; printf("%d%d",4+card,card); a) 45 b) 51 c) 54 d) 55 e) ไมมขอใดถก

35. ขอใดคอผลลพธเม0อจบโปรแกรม int a=1,b=5,c=2; a+=b-c; printf("%d",a); printf("%d",b); a) 33 b) 35 c) 34 d) 43 e) 45

36. ขอใดคอผลลพธเม0อจบโปรแกรม int a=2,b=3,c=0;

c=a+b*6/b*(a+1);

printf("%d",c);

a) 18 b) 19 c) 20 d) 22 e) 26

0 1 0 1 1 0 1 #

0 1 1 #

0 1 1 #

0 1 0 #

0 1 0 #

int x="5";

int a,ab,abc='555';

char tv="C";

float abcd;

int x=1,int y=2;

.A

All star

_php

1Step

break

Page 5: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

5 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

37. ขอใดคอผลลพธเม0อจบโปรแกรม int a=5,b=1,c=3,A=-1;

A=A+a*A-a/A*(b+c);

printf("%d",A);

a) 14 b) -14 c) -1 d) -60 e) 0

38. ขอใดคอผลลพธเม0อจบโปรแกรม

int t=2,v=3,ch=10;

ch=ch+t%v+t*2;

printf("%d",ch);

a) 20 b) 16

c) 12 d) 4 e) ไมมขอใดถก

39. ขอใดคอผลลพธเม0อจบโปรแกรม int h=3;

printf("%d",h+2);

printf("%d",h++);

printf("%d",h);

printf("%d",--h);

printf("%d",h);

a) 35654 b) 55655 c) 33433 d) 53433 e) ไมมขอใดถก

40. ขอใดคอผลลพธเม0อจบโปรแกรม int a=7,b=3,c=1,d;

d=a*c+ --b +a*c;

printf("%d",d);

a) 14 b) 15 c) 16 d) 17 e) 18

41. ขอใดคอผลลพธเม0อจบโปรแกรม

int x=4,y=1,z=2;

z=x/z- ++y *z;

printf("%d",z);

a) 4 b) 2

c) 0 d) -2 e) -4

42. ขอใดคอผลลพธเม0อจบโปรแกรม

int x=5,y=2,z=1;

z+=y*x-y++ * --x;

printf("%d",z);

a) 1 b) 0

c) -1 d) 2 e) ไมมขอใดถก

43. ขอใดคอผลลพธเม0อจบโปรแกรม int a=2,A=6; if(A>=a){ printf("A"); } printf("B"); a) AB b) A

c) B d) ไมมผลลพธปรากฏ e) เกด Runtime Error

44. ขอใดคอผลลพธเม0อจบโปรแกรม int x=4,y=5; if(y==x) printf("%d",x*y-1); else printf("%d",4*x-y); a) 19 b) 11 c) -4 d) 24 e) ไมมผลลพธปรากฏ

45. จากโปรแกรมในขอท0ผานมา ถาเปล0ยน x=4 ในบรรทดแรก เปน x=5 จะเกดผลลพธตามขอใด a) 19 b) 11 c) -4 d) 24 e) ไมมผลลพธปรากฏ

Page 6: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

6 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

46. ขอใดคอผลลพธเม0อจบโปรแกรม int n=191,m=2; if(n%m==1) printf("Odd"); else printf("Even"); a) Odd b) Even c) OddEven d) ไมมผลลพธปรากฏ e) เกด Runtime Error

47. ขอใดคอผลลพธเม0อจบโปรแกรม int pop=-1,eye=8; if(pop>=-5&&(++eye)<=8)

printf("Cheer%d",eye); a) Cheer b) Cheer8

c) Cheer9 d) Cheer%d e) ไมมผลลพธปรากฏ

48. ขอใดคอผลลพธเม0อจบโปรแกรม int creep=9,hero=6; if(creep==(hero++))

printf("Mega"); printf("Kill"); if(hero>6)

printf("All"); a) GodLike b) MegaKill c) Kill d) KillAll e) ไมมขอใดถก

49. ขอใดคอผลลพธเม0อจบโปรแกรม int x=1,y=2,z=3; if(z<=y&&y==0)

{

printf("X");

}else{

if(x!=y||x!=z)

printf("Y");

printf("Z");

}

a) X b) Y c) YZ d) XYZ e) ไมมขอใดถก

50. ขอใดคอผลลพธเม0อจบโปรแกรม int score=100; //score=15; if(score>=20) printf("A"); else if(score>=10) printf("B"); else if(score>=5) printf("C"); else if(score>=0) printf("D"); else printf("F"); a) A b) F

c) AF d) ABCD e) ABCDF

51. จากโปรแกรมในขอท0ผานมา ถาเปล0ยน int score=100 ในบรรทดแรกเปน score=-100 จะเกดผลลพธขอใด a) ABCDEF b) F c) DF d) ไมมผลลพธใดๆปรากฏ e) เกด Runtime Error

52. เม0อจบโปรแกรมคาของ x จะมคาเปนเทาใด int g=3,x=2,z=1;

switch(g){

case 1 :

case 2 : x++; break;

case 3 : x++;

case 4 : x++; break;

case 5 : z--;

default : x--; z++;

}

a) 2 b) 3

c) 4 d) 5 e) ไมมคาตอบ

53. จากโจทยขอท0ผานมา ถาเปล0ยน g=3 เปน g=1 แลวเร0มรนโปรแกรมใหม เม0อจบโปรแกรมแลว คาของ x+z จะมคาเปนเทาใด a) 4 b) 3 c) 2 d) 1 e) ไมมคาตอบ

Page 7: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

7 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

54. เม0อจบโปรแกรมคาของ sum เปนเทาใด ? int i,sum=0; for(i=0;i<10;i++) { sum=sum+1; } a) 0 b) 9 c) 10 d) 11 e) 12

55. เม0อจบโปรแกรมคาของ sum เปนเทาใด ?

int j,sum=0; for(j=1;j<=9;j++){ sum++; } a) 8 b) 9 c) 10 d) 11 e) 12

56. เม0อจบโปรแกรมคาของ x เปนเทาใด ? int i,x=-5,y=2; for(i=10;i>=y;i--) x++; a) 8 b) 7 c) 5 d) 4 e) 2

57. เม0อจบโปรแกรมคาของ sum เปนเทาใด ? int i,sum=0; for(i=1;i<=10;i++) sum=sum+i; a) 45 b) 55 c) 56 d) 65 e) 0

58. ขอใดคอผลลพธเม0อจบโปรแกรม int i,x=11;

for(i=x-1;i>=5;i--)

x--;

x--;

printf("%d",x);

a) 12 b) 10 c) 6 d) 5 e) 4

59. ผลลพธเม0อจบโปรแกรมจะเปนขอใด ? for(int u=1;u<3;u++)

printf("X");

printf("Y");

a) XXY b) XXXY c) XXXYYY d) XYXYXY e) ไมมขอใดถก

60. เม0อจบโปรแกรมคาของ sum เปนเทาใด ? int x,sum=0;

for(x=1;x<=100;x++)

if(x%2==0)

sum=sum+x;

a) 0 b) 2500 c) 2550 d) 2601 e) ไมมผลลพธปรากฏ

61. จากโปรแกรมขอท0ผานมา เกดการวนซ. าใน For Loop ท.งหมดก0รอบ a) นอยกวา 50 รอบ b) >=50 แต <100 รอบ c) 100 รอบพอด d) มากกวา 100 รอบ e) ไมมขอใดถก

62. ขอใดกลาวถกตองเก0ยวกบตวแปร sum เม0อจบการทาโปรแกรมในขอ 60 a) มคาเทากบผลบวกเลขต.งแต 0 ถง 100 b) มคาเทากบผลบวกเลขต.งแต 1 ถง 100 c) มคาเทากบผลบวกของเลขค0ต.งแตเลข 1 ถง 100 d) มคาเทากบผลบวกของเลขคต.งแตเลข 1 ถง 100 e) ไมมขอใดถก

63. เม0อจบโปรแกรมคาของ t เปนเทาใด ? int i=0,t=100; while(t>20) { t--; } a) 21 b) 20

c) 19 d) 18 e) ไมมขอใดถก

Page 8: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

8 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

64. เม0อจบโปรแกรมคาของ sum เปนเทาใด ? int i=0,sum=0; while(i<11) { sum+=i; i++; } a) 10 b) 11 c) 55 d) 66 e) 110

65. เม0อจบโปรแกรมคาของ s เปนเทาใด ? int r=0,x=0,s=5; while(r!=x) s++; s--; a) 0 b) 4 c) 5 d) 6 e) เกด Infinity loop

66. เม0อรนโปรแกรมในขอใดทาใหเกดลปท0ไมส.นสด

(Infinity loop)

a) b) c) d) e) มคาตอบมากกวา 1 ขอ

67. เม0อจบโปรแกรมคาของ q เปนเทาใด ? int i=10,q=100; while(i!=q) { i++; q--; } a) 50 b) 51 c) 53 d) 55 e) 56

68. เม0อจบโปรแกรมคาของ sum เปนเทาใด ? int x=0; int sum=0; do{ sum++; x++; }while(x<10); a) 11 b) 10

c) 9 d) 8 e) ไมมขอใดถก

69. เม0อจบโปรแกรมผลลพธท0ออกมาคอขอใด int f=2,g=4; do{ f++; }while(f<=10); g--; printf("%d",(f+g)); a) 13 b) 14 c) 15 d) 16 e) Runtime Error

70. เม0อจบโปรแกรมผลลพธท0ออกมาคอขอใด int m=12,r=1;

do{

m--;

r=r+2;

}while(m>=5);

printf("%d",r); a) 14 b) 15

c) 16 d) 17 e) 18

int r=2,c=3,x=4;

while((c+x+r)!=0){

c-=2;

x+=1;

}

int h=150;

while(h>=100)

{

h++;

}

int w=4;

while(w==4){

if(w%2==1)

w--;

}

int r=5,z=1;

while(r<50){

if(z<0) r++;

z--;

}

Page 9: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

9 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

71. เม0อจบโปรแกรมผลลพธท0ออกมาคอขอใด int z=10,y=1; do{ z=z-y; y++; }while(z>=-5); printf("%d",z); a) 11 b) 5 c) 0 d) -5 e) -11

72. จากขอท0ผานมา มการวนซ. าท.งหมดก0รอบ a) 8 b) 7

c) 6 d) 5 e) ไมมขอใดถก

73. เม0อจบโปรแกรมขอใดคอคาของ k+t

int k=1,m=2,i=3,t=4,l=5;

k=l*t/m;

for(i=2;i<=l;i+=2){

if(i%m==0){

k++;

}else{

t--;

}

}

a) 10 b) 12 c) 14 d) 16 e) ไมมคาตอบ

74. เม0อจบโปรแกรมผลลพธท0ออกมาคอขอใด int root=2;

if(root) root++;

else root--;

printf("%d",root);

a) 3 b) 2 c) 1 d) 0 e) Runtime Error

75. เม0อจบโปรแกรมผลลพธท0ออกมาคอขอใด

int angry=1,bird=1;

while(bird){

if(angry%2==0)

break;

angry++;

}

printf("%d%d",angry,bird);

a) 10 b) 11

c) 21 d) Runtime Error e) เกด Infinity Loop

76. เม0อจบโปรแกรมผลลพธท0ออกมาคอขอใด

int s=65,t=6;

while(t){

s++;

t--;

}

printf("%c",s); a) 70 b) 71

c) F d) G e) ไมมขอใดถก

77. เม0อจบโปรแกรมจงหาคา m+k; int k=9,m=3,i=0,t=6,l=5;

for(;i<3;i++){

if((m+l)%3==2){

while(t<10){

m++;

t++;

}

}

k--;

}

a) 9 b) 10 c) 11 d) 12 e) ไมมคาตอบ

Page 10: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

10 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

#include(stdio.h)

Int main()

{

int d1=5,d2=4,d3=2,n,i;

scanf("%d",n);

if(d3!=d1&&d2>d)

{

for(i=10,i>=0,i--)

{

a+=b

}else

printf("\No "^-^"");

}

return 0

}

#include<studio.h>

void main()

{

int continue,a,b=5,c=12;

scanf("%f",&d1);

do{

if(c+b==a) c--;

}

Else

{

printf["Oh"];

}

}while(a==(!b))

getch();

}

78. เม0อจบโปรแกรมขอใดคอคาของ d+o

int d=0,o=1,t=4,a=10;

t=2* ++d + d * t;

for(int i=d;i<=t;){

o++;

if(!(o%i==0))

d--;

i=i+o;

}

a) 2 b) 3 c) 4 d) 5 e) ไมมคาตอบ

79. เม0อจบโปรแกรมตอไปน.จะมตวอกษร * ถกพมพออกมาก0ตวอกษร int e,w;

for(e=3;e<=4;e++)

for(w=4;w>2;w--)

printf("*");

a) 4 b) 6 c) 8 d) 10 e) ไมมคาตอบ

80. การกาหนดคา a และ b ในขอใดใหผลลพธออกมาเปน KMITL

a) a=3,b=0 b) a=5,b=0 c) a=3,b=1 d) a=5,b=1 e) ไมมคาตอบ

จากคาส0งในโปรแกรมตอไปน. จงแกไขเพ0อใหสามารถคอมไพลได (ไมเกด Compile Error)

a>=2

int a=???,b=???

ENG

Start

a<4&&!b

COM KMITL

End

True

True

False

False

Page 11: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

11 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

จงเขยนโปรแกรมหาคานอยท0สด และคามากท0สด จากขอมลท0กาหนดให และแสดงผลออกทางจอภาพ

ขอมลนาเขา

บรรทดแรก จานวนเตมบวก n (1 <= n <= 1,000) บงบอกถงจานวนขอมลท0โจทยกาหนดให บรรทดท� 2 ถง n+1 จานวนเตมบวก Ai เปนขอมลท.งหมด ( -2,000,000,000 <= Ai <= 2,000,000,000) ขอมลสงออก บรรทดแรก จานวนเตมบวก m แสดงจานวนท0มคานอยท0สดในชดขอมลท0โจทยกาหนด บรรทดท�สอง จานวนเตมบวก M แสดงจานวนท0มคามากท0สดในชดขอมลท0โจทยกาหนด ท�มา: Programming.in.th (Northern_series)

Page 12: c Programming Part1 v3.5 2

© By Q 3D/2 (CE KMITL 49)(RSix)

http://aikkew.kmi.tl/c

[email protected]

12 แบบฝกความเขาใจการเขยนโปรแกรมดวยภาษา C Last update : 8 กรกฎาคม ���� (Version 3.5)

จงเขยน Flowchart ของคาส0ง for ,while ,do…while

อางอง (Reference) http://www.ce.kmitl.ac.th http://www.cprogramming.com http://www.vcharkarn.com/varticle/18065

Operator priority# Operator Description Associativity

1

() [] . ->

++ --

Parentheses (function call) (see Note 1) Brackets (array subscript) Member selection via object name Member selection via pointer Postfix increment/decrement

left-to-right

2

++ -- + - ! ~ (type)

* &

sizeof

Prefix increment/decrement Unary plus/minus Logical negation/bitwise complement Cast (change type) Dereference Address Determine size in bytes

right-to-left

3 * / % Multiplication/division/modulus left-to-right

4 + - Addition/subtraction left-to-right

5 << >> Bitwise shift left, Bitwise shift right left-to-right

6 < <= > >=

Relational less than/less than or equal to

left-to-right

Relational greater than/greater than or equal to

7 == != Relational is equal to/is not equal to

left-to-right

8 & Bitwise AND left-to-right

9 ^ Bitwise exclusive OR left-to-right

10 | Bitwise inclusive OR left-to-right

11 && Logical AND left-to-right

12 || Logical OR left-to-right

13 ?: Ternary conditional right-to-left

14

= += -= *= /= %= &= ^= |= <<= >>

=

Assignment Addition/subtraction assignment Multiplication/division assignment Modulus/bitwise AND assignment Bitwise exclusive/inclusive OR assignment Bitwise shift left/right assignment

right-to-left

15 , Comma (separate expressions) left-to-right

แหลงขอมล (source) : http://www.difranco.net/cop2220/op-prec.htm

While For

Do…while