คอมพิวเตอร์โอลิมปิก
Click here to load reader
-
Upload
sumalee-sonamthiang -
Category
Education
-
view
40 -
download
1
Transcript of คอมพิวเตอร์โอลิมปิก
![Page 1: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/1.jpg)
คอมพิ�วเตอร์โอลิ�มปิ�ก ค�าย 1
ศู�นย์� สอวน. คณะว�ทย์าศูาสตร์�มหาว�ทย์าลั�ย์อ�บลัร์าชธาน�
![Page 2: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/2.jpg)
ร์�ปิแบบการ์ร์�บแลิะแสดงผลิข้�อม�ลิ
ในภาษา C แลิะ C++
ผู้��สอนดร์. ส�มาลั� เฮงย์ศูมาก
Email : [email protected]
![Page 3: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/3.jpg)
ในภาษา C จะม�ฟั&งก�ช�นส'าหร์�บการ์พิ�มพิ�แลัะการ์ร์�บข้�อม�ลัไว� ให�ใช�มากมาย์
การ์พิ�มพิ�ก,ค-อ การ์น'าข้�อม�ลัไปแสดงท�/หน�าจอ (output) การ์ร์�บข้�อม�ลัก,ค-อ การ์ร์�บข้�อม�ลัจากค�ย์�บอร์�ดเข้�ามา
(input) ในภาษา C น�0นจะมองอ�ปกร์ณ�ในเคร์-/องคอมพิ�วเตอร์�เป1นไฟัลั�
ท�0งหมด ย์กต�วอย์2างเช2น จอภาพิจะเป1น Standard Output File แลัะค�ย์�บอร์�ดจะเป1น Standard Input File
การ์ร์�บแลิะการ์แสดงผลิข้�อม�ลิ
![Page 4: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/4.jpg)
![Page 5: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/5.jpg)
ฟั&งก�ช�น ใน stdio.h
การ์แสดงข้�อความออกทางหน�าจอ
![Page 6: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/6.jpg)
printf (เป1นฟั&งก�ช�นมาตร์ฐานข้อง C ใน stdio)◦ปิร์ะกาศ stdio ในส2วน Preprocessor Directive
◦ก2อนเร์�ย์กใช�ฟั&งก�ช�น printf ใน mainร์�ปิแบบ printf(“control string”, variable,…);◦variable เป1นต�วแปร์ใช�เก,บค2า (ท�/เปลั�/ย์นแปลังได�) ใน Memory ในข้ณะปร์ะมวลัผู้ลั
6
ค'าส�(งแสดงผลิ ด�วย printf
control string ปร์ะกอบด�วย์ ข้�อความอธ�บาย์ เช2น printf(“C Programming”);
%format เช2น %d, %f, %c, %s
อ�กษร์ควบค�ม เช2น \n (new line), …
%d ส'าหร์�บ integer หร์-อ decimal %f ส'าหร์�บ real หร์-อ floating point
…
Memory
variable
![Page 7: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/7.jpg)
ต�วอย�างโปิร์แกร์มแสดงผลิข้�อม�ลิ
![Page 8: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/8.jpg)
ในส2วนร์�ปแบบข้�อความอธ�บาย์น�0น อาจจะเป1นต�วอ�กษร์ ข้�อความ ต�วเลัข้ หร์-อเป1นต�วก'าหนดชน�ดข้องข้�อม�ลั ซึ่6/ง
ใช�ก'าหนดชน�ดข้�อม�ลัท�/จะพิ�มพิ� ซึ่6/งจะต�องอย์�2หลั�งคร์-/อง หมาย์ % เสมอแลัะสามาร์ถใช�ได�ท� 0ง การ์ร์�บแลัะแสดงผู้ลั ข้�อม�ลั ด�งแสดงในตาร์าง
ชน�ดข้�อม�ลั ข้นาด ร์ห�ส ต�วอย์2างchar - c %c
short intint
long int
h-
i or l
ddd
%hd%d%ld
floatdouble
long double
--l
fff
%f%f%lf
![Page 9: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/9.jpg)
d /* int, signed base 10 */ i /* int, signed base 10 */ o /* int, unsigned base 8, no leading 0 */ x /* int, unsigned base 16, abcdef with no leading 0x */ X /* int, unsigned base 16, ABCDEF with no leading 0X */ u /* int, unsigned base 10 */ s /* char *, nul terminated sequence of characters */ c /* int, single character */ f /* double, notation [-]mm.dd */ e /* double, notation [-]m.dde[+/-]xx */ E /* double, notation [-]m.ddE[+/-]xx */ g /* double, %e if exponent is less than -4 or >= the precision, %f otherwise */ G /* double, %E if exponent is less than -4 or >= the precision, %f otherwise */ p /* void *, implementation dependent representation */ n /* int *, the number of characters written so far. Assigned to the argument */ % /* print a % character */
การ์ก'าหนดร์�ปิแบบการ์แสดงผลิ ด�วยต�วควบค)ม
![Page 10: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/10.jpg)
1. #include <stdio.h> 2. int main ( void )3. {4. printf ( "%5d\n", 123 ); 5. printf ( "%*d\n", 5, 123 ); 6. printf ( "%+05d\n", 123 ); 7. printf ( "%x\n", 123U ); 8. printf ( "%#x\n", 123U ); 9. printf ( "%#X\n", 123U ); 10. printf ( "%-10.2f\n", 12.3 ); 11. printf ( "%10.2f\n", 12.3 ); 12. printf ( "%lu\n", 123UL ); 13. printf ( "%s\n", "Testing" ); 14. printf ( "%c\n", 'A' ); 15. return 0;16. }
แบบฝึ+กห�ดท,( 2
![Page 11: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/11.jpg)
1. #include <stdio.h> 2. int main ( void )3. {4. printf ( "%5d\n", 123 ); /* Prints " 123" */5. printf ( "%*d\n", 5, 123 ); /* Prints " 123" */6. printf ( "%+05d\n", 123 ); /* Prints "+0123" */7. printf ( "%x\n", 123U ); /* Prints "7b" */8. printf ( "%#x\n", 123U ); /* Prints "0x7b" */9. printf ( "%#X\n", 123U ); /* Prints "0X7B" */10. printf ( "%-10.2f\n", 12.3 ); /* Prints "12.30" */11. printf ( "%10.2f\n", 12.3 ); /* Prints " 12.30" */12. printf ( "%lu\n", 123UL ); /* Prints "123" */13. printf ( "%s\n", "Testing" ); /* Prints "Testing" */14. printf ( "%c\n", 'A' ); /* Prints "A" */15. return 0;16. }
Output ข้องแบบฝึ+กห�ดท,( 2
![Page 12: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/12.jpg)
จงเข้�ย์นโปร์แกร์มเพิ-/อร์�บข้�อม�ลัเลัข้๗นวน
แบบฝึ+กห�ดท,( 3
![Page 13: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/13.jpg)
ฟั&งก�ช�น ใน math.h
ฟั.งกชั�นค'านวณทางคณ�ตศาสตร์
![Page 14: คอมพิวเตอร์โอลิมปิก](https://reader038.fdocument.pub/reader038/viewer/2022100508/55c3877abb61ebeb7a8b4919/html5/thumbnails/14.jpg)
เข้�ย์นโปร์แกร์ม พิ�มพิ�ค'าว2า C Programming
14