SlideShare uma empresa Scribd logo
1 de 6
Baixar para ler offline
แบบบันทึกการศึกษาค้นคว้าและการแก้ปัญหา

                  โจทย์ปัญหา PBL 2 เรื่อง โครงสร้างของโปรแกรมภาษาซี

         รายวิชาการเขียนโปรแกรมภาษาซีเบื้องต้น ง30201 ระดับชั้นมัธยมศึกษาปีที่ 4

สมาชิกในกลุ่ม

   1. นางสาวนพรัตน์ อนุสงค์           เลขที่ 7
   2. นางสาววิภาวรรณ ภูติรักษ์        เลขที่ 8
   3. นางสาวอุทัยวรรณ นาสุข           เลขที่ 9




ภารกิจ

1. จากสถานการณ์ปัญหาที่มีนานุชและเพื่อนพบในขณะนี้มีสาเหตุมาจากสิ่งใด มีนานุชจะต้องแก้ปัญหานี้
อย่างไร (1 คะแนน)
2. จากสถานการณ์นี้ สิ่งที่มีนานุชควรรู้เกี่ยวกับโครงสร้างของโปรแกรมภาษาซี มีองค์ประกอบที่สาคัญ
อะไรบ้าง และวิธีการเขียนคอมเมนต์ (Comment) มีกี่ประเภท มีวิธีเขียนอย่างไร (1 คะแนน)

3. มีนานุชควรสืบค้นตัวอย่างโปรแกรมภาษาซีจากเว็บไซต์ใด และมีรายละเอียดของตัวอย่างโปรแกรม
ภาษาซีเป็นอย่างไร (1 คะแนน)

4. นักเรียนช่วยอธิบายโปรแกรมทีละบรรทัดด้วยว่า โปรแกรมที่สืบค้นมานั้นเป็นส่วนประกอบใดของ
โครงสร้างภาษาซี โดยใช้คอมเมนต์ (Comment) ในการเขียนคาอธิบาย (2 คะแนน)

ตอนที่ 1

    หัวข้อปัญหา โครงสร้างของโปรแกรมภาษาซี

    ทาความเข้าใจปัญหา ศึกษาโครงสร้างของโปรแกรมและการเขียนคอมเมนต์(Comment)
    - สิ่งที่ต้องการรู้ โครงสร้างของโปรแกรมภาษาซีมีอะไรบ้าง แต่ละส่วนมีลักษณ์สาคัญอย่างไร โดย
       ใช้คอมเมนต์(Comment) ในการเขียนอธิบายโครงสร้างของโปรแกรม
    - วิธี ก ารหาคาตอบ ประชุ ม แบ่ง หน้าที่ ศึก ษาค้นคว้าข้อมูล และรวบรวมข้อมูล นาข้อมูล ที่ไ ด้มา
       วิเคราะห์และตอบคาถาม
    การศึกษาค้นคว้า / แก้ปัญหา
               ชื่อสมาชิก             การแบ่งหน้าที่                แหล่งข้อมูล/อ้างอิง
    นางสาวนพรัตน์ อนุสงค์          รวบรวมข้อมูลและ
                                   วิเคราะห์ข้อมูลสืบค้น
                                   ข้อมูล

    นางสาววิภาวรรณ ภูติรักษ์       วิเคราะห์ปัญหาและ
                                   ตอบคาถาม

    นางสาวอุทัยวรรณ นาสุข          สืบค้นข้อมูล            http://kroohathaichon.wordpress.com


ตอนที่ 2 สรุปผลการศึกษาค้นคว้า / แก้ปัญหาตามภารกิจ

1.จากสถานการณ์ปัญหาที่มีนานุชและเพื่อนพบในขณะนี้มีสาเหตุมาจากสิ่งใด มีนานุชจะต้องแก้ปัญหานี้
อย่างไร (1 คะแนน)
ตอบ จากสถานการณ์ปัญหาที่มีนานุชและเพื่อนพบในขณะนี้มีสาเหตุมาจากนีนานุชและเพื่อนต้องการ
ทราบว่าโครงสร้างของโปรแกรมภาษาซีมีอะไรบ้าง แต่ละส่วนมีลักษณ์สาคัญอย่างไร โดยใช้คอมเมนต์
(Comment) ในการเขียนอธิบายโครงสร้างของโปรแกรมมีนานุชและเพื่อนจะต้องแก้ปัญหานี้โดยการเริ่ม
ศึกษาค้นคว้าข้อมูลเกี่ยวกับโครงสร้างของภาษาซี

2. จากสถานการณ์นี้ สิ่งที่มีนานุชควรรู้เกี่ยวกับโครงสร้างของโปรแกรมภาษาซี มีองค์ประกอบที่สาคัญ
อะไรบ้าง และวิธีการเขียนคอมเมนต์ (Comment) มีกี่ประเภท มีวิธีเขียนอย่างไร                (1 คะแนน)

ตอบ โครงสร้างของโปรแกรมภาษาซีแบ่งออกเป็น 3 ส่วน

1. ส่วนหัวของโปรแกรม

      ส่วนหัวของโปรแกรมนี้เรียกว่า Preprocessing Directive ใช้ระบุเพื่อบอกให้คอมไพเลอร์กระทาการ
ใด ๆ ก่อนการแปลผลโปรแกรมในที่นี่คาสั่ง #include <stdio.h> ใช้บอกกับคอมไพเลอร์ให้นาเฮดเดอร์ไฟล์
ที่ระบุคือ stdio.h เข้าร่วมในการแปลโปรแกรมด้วย โดยการกาหนด preprocessing directives นี้จะต้อง
ขึ้นต้นด้วยเครื่องหมาย # เสมอ คาสั่งที่ใช้ระบุให้คอมไพเลอร์นาเฮดเดอร์ไฟล์เข้าร่วมในการแปล
โปรแกรม สามารถเขียนได้ 2 รูปแบบ คือ

- #include < ชื่อเฮดเดอร์ไฟล์ > คอมไพเลอร์จะทาการค้นหาเฮดเดอร์ไฟล์ที่ระบุจากไดเรกทอรีที่ใช้สาหรับ
เก็บเฮดเดอร์ไฟล์โดยเฉพาะ ( ปกติคือไดเรกทอรีชื่อ include)

- #include “ ชื่อเฮดเดอร์ไฟล์ ” คอมไพเลอร์จะทาการค้นหาเฮดเดอร์ไฟที่ระบุ จากไดเร็คทอรีเดียวกันกับ
ไฟล์ source code นั้น แต้ถ้าไม่พบก็จะไปค้นหาไดเร็คทอรีที่ใช้เก็บ เฮดเดอร์ไฟล์โดยเฉพาะ

2. ส่วนของฟังก์ชั่นหลัก

      ฟังก์ชั่นหลักของภาษาซี คือ ฟังก์ชั่น main( ) ซึ่งโปรแกรมภาษาซีทุกโปรแกรมจะต้องมีฟังก์ชั่นนี้อยู่
ในโปรแกรมเสมอ จะเห็นได้จากชื่อฟังก์ชั่นคือ main แปลว่า “ หลัก ” ดังนั้น การเขียนโปรแกรมภาษซีจึง
ขาดฟังก์ชั่นนี้ไปไม่ได้ โดยขอบเขตของฟังก์ชั่นจะถูกกาหนดด้วยเครื่องหมาย { และ } กล่าวคือ การทางาน
ของฟังก์ชั่นจะเริ่มต้นที่เครื่องหมาย { และจะสิ้นสุดที่เครื่องหมาย } ฟังก์ชั่น main( ) สามารถเขียนใน
รูปแบบของ void main(void) ก็ได้มีความหมายเหมือนกัน คือ หมายความว่า ฟังก์ชั่น main() จะไม่มี
อาร์กิวเมนต์ (argument) คือไม่มีการรับค่าใด ๆ เข้ามาประมวลผลภายในฟังก์ชั่น และจะไม่มีการคืนค่าใด ๆ
กลับออกไปจากฟังก์ชั่นด้วย




3. ส่วนรายละเอียดของโปรแกรม

เป็นส่วนของการเขียนคาสั่ง เพื่อให้โปรแกรมทางานตามที่ได้ออกแบบไว้

คอมเมนต์ในภาษาซี

คอมเมนต์ (comment) คือส่วนที่เป็นหมายเหตุของโปรแกรม มีไว้เพื่อให้ผู้เขียนโปรแกรมใส่ข้อความอธิบาย
กากับลงไปใน source code ซึ่งคอมไพเลอร์จะข้ามาการแปลผลในส่วนที่เป็นคอมเมนต์นี้ คอมเมนต์ใน
ภาษาซีมี 2 แบบคือ

„ คอมเมนต์แบบบรรทัดเดียว ใช้เครื่องหมาย //

„ คอมเมนต์แบบหลายบรรทัด ใช้เครื่องหมาย /* และ */

3. มีนานุชควรสืบค้นตัวอย่างโปรแกรมภาษาซีจากเว็บไซต์ใด และมีรายละเอียดของตัวอย่างโปรแกรม
ภาษาซีเป็นอย่างไร (1 คะแนน)

ตอบ มีนานุชควรสืบค้นตัวอย่างโปรแกรมภาษาซีจากเว็บไซต์ http://blog.eduzones.com และมีรายละเอียด
ดังนี้ ตัวอย่างของโปรแกรม การบวกค่าจานวนเต็ม 2 จานวนเข้าด้วยกัน แล้วแสดงผลลัพธ์ออกทางหน้าจอ
การเขียนโปรแกรมเพื่อแก้ปัญหานี้ สามารถเขียนได้ดังนี้
#include
void main()

{

    int N1, N2, Sum;

         printf("please input an integer number : ");

         scanf("%d",&N1);

         printf("please input another integer number : ");

         scanf("%d",&N2);

         Sum = N1 + N2;

         printf("so, %d + %d = %d",N1,N2,Sum);

}

4. นักเรียนช่วยอธิบายโปรแกรมทีละบรรทัดด้วยว่า โปรแกรมที่สืบค้นมานั้นเป็นส่วนประกอบใดของ
โครงสร้างภาษาซี โดยใช้คอมเมนต์ (Comment) ในการเขียนคาอธิบาย (2 คะแนน)

ตอบ              #include //ส่วนหัวของโปรแกรม

                 void main() //ฟังก์ชันหลัก

                { /*เริ่มต้นการเขียนโปรแกรมด้วยปากกาเปิด*/

                  int N1, N2, Sum; //ประกาศตัวแปร

                   printf("please input an integer number : "); /*ส่วนรายละเอียดของโปรแกรม

                   scanf("%d",&N1);

                   printf("please input another integer number : ");

                  scanf("%d",&N2);
Sum = N1 + N2;

printf("so, %d + %d = %d",N1,N2,Sum); */

} /*จบการเขียนโปรแกรมด้วยเครื่องหมายปากาปิด*/

Mais conteúdo relacionado

Destaque

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destaque (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

โจทย์ Pbl 2

  • 1. แบบบันทึกการศึกษาค้นคว้าและการแก้ปัญหา โจทย์ปัญหา PBL 2 เรื่อง โครงสร้างของโปรแกรมภาษาซี รายวิชาการเขียนโปรแกรมภาษาซีเบื้องต้น ง30201 ระดับชั้นมัธยมศึกษาปีที่ 4 สมาชิกในกลุ่ม 1. นางสาวนพรัตน์ อนุสงค์ เลขที่ 7 2. นางสาววิภาวรรณ ภูติรักษ์ เลขที่ 8 3. นางสาวอุทัยวรรณ นาสุข เลขที่ 9 ภารกิจ 1. จากสถานการณ์ปัญหาที่มีนานุชและเพื่อนพบในขณะนี้มีสาเหตุมาจากสิ่งใด มีนานุชจะต้องแก้ปัญหานี้ อย่างไร (1 คะแนน)
  • 2. 2. จากสถานการณ์นี้ สิ่งที่มีนานุชควรรู้เกี่ยวกับโครงสร้างของโปรแกรมภาษาซี มีองค์ประกอบที่สาคัญ อะไรบ้าง และวิธีการเขียนคอมเมนต์ (Comment) มีกี่ประเภท มีวิธีเขียนอย่างไร (1 คะแนน) 3. มีนานุชควรสืบค้นตัวอย่างโปรแกรมภาษาซีจากเว็บไซต์ใด และมีรายละเอียดของตัวอย่างโปรแกรม ภาษาซีเป็นอย่างไร (1 คะแนน) 4. นักเรียนช่วยอธิบายโปรแกรมทีละบรรทัดด้วยว่า โปรแกรมที่สืบค้นมานั้นเป็นส่วนประกอบใดของ โครงสร้างภาษาซี โดยใช้คอมเมนต์ (Comment) ในการเขียนคาอธิบาย (2 คะแนน) ตอนที่ 1 หัวข้อปัญหา โครงสร้างของโปรแกรมภาษาซี ทาความเข้าใจปัญหา ศึกษาโครงสร้างของโปรแกรมและการเขียนคอมเมนต์(Comment) - สิ่งที่ต้องการรู้ โครงสร้างของโปรแกรมภาษาซีมีอะไรบ้าง แต่ละส่วนมีลักษณ์สาคัญอย่างไร โดย ใช้คอมเมนต์(Comment) ในการเขียนอธิบายโครงสร้างของโปรแกรม - วิธี ก ารหาคาตอบ ประชุ ม แบ่ง หน้าที่ ศึก ษาค้นคว้าข้อมูล และรวบรวมข้อมูล นาข้อมูล ที่ไ ด้มา วิเคราะห์และตอบคาถาม การศึกษาค้นคว้า / แก้ปัญหา ชื่อสมาชิก การแบ่งหน้าที่ แหล่งข้อมูล/อ้างอิง นางสาวนพรัตน์ อนุสงค์ รวบรวมข้อมูลและ วิเคราะห์ข้อมูลสืบค้น ข้อมูล นางสาววิภาวรรณ ภูติรักษ์ วิเคราะห์ปัญหาและ ตอบคาถาม นางสาวอุทัยวรรณ นาสุข สืบค้นข้อมูล http://kroohathaichon.wordpress.com ตอนที่ 2 สรุปผลการศึกษาค้นคว้า / แก้ปัญหาตามภารกิจ 1.จากสถานการณ์ปัญหาที่มีนานุชและเพื่อนพบในขณะนี้มีสาเหตุมาจากสิ่งใด มีนานุชจะต้องแก้ปัญหานี้ อย่างไร (1 คะแนน)
  • 3. ตอบ จากสถานการณ์ปัญหาที่มีนานุชและเพื่อนพบในขณะนี้มีสาเหตุมาจากนีนานุชและเพื่อนต้องการ ทราบว่าโครงสร้างของโปรแกรมภาษาซีมีอะไรบ้าง แต่ละส่วนมีลักษณ์สาคัญอย่างไร โดยใช้คอมเมนต์ (Comment) ในการเขียนอธิบายโครงสร้างของโปรแกรมมีนานุชและเพื่อนจะต้องแก้ปัญหานี้โดยการเริ่ม ศึกษาค้นคว้าข้อมูลเกี่ยวกับโครงสร้างของภาษาซี 2. จากสถานการณ์นี้ สิ่งที่มีนานุชควรรู้เกี่ยวกับโครงสร้างของโปรแกรมภาษาซี มีองค์ประกอบที่สาคัญ อะไรบ้าง และวิธีการเขียนคอมเมนต์ (Comment) มีกี่ประเภท มีวิธีเขียนอย่างไร (1 คะแนน) ตอบ โครงสร้างของโปรแกรมภาษาซีแบ่งออกเป็น 3 ส่วน 1. ส่วนหัวของโปรแกรม ส่วนหัวของโปรแกรมนี้เรียกว่า Preprocessing Directive ใช้ระบุเพื่อบอกให้คอมไพเลอร์กระทาการ ใด ๆ ก่อนการแปลผลโปรแกรมในที่นี่คาสั่ง #include <stdio.h> ใช้บอกกับคอมไพเลอร์ให้นาเฮดเดอร์ไฟล์ ที่ระบุคือ stdio.h เข้าร่วมในการแปลโปรแกรมด้วย โดยการกาหนด preprocessing directives นี้จะต้อง ขึ้นต้นด้วยเครื่องหมาย # เสมอ คาสั่งที่ใช้ระบุให้คอมไพเลอร์นาเฮดเดอร์ไฟล์เข้าร่วมในการแปล โปรแกรม สามารถเขียนได้ 2 รูปแบบ คือ - #include < ชื่อเฮดเดอร์ไฟล์ > คอมไพเลอร์จะทาการค้นหาเฮดเดอร์ไฟล์ที่ระบุจากไดเรกทอรีที่ใช้สาหรับ เก็บเฮดเดอร์ไฟล์โดยเฉพาะ ( ปกติคือไดเรกทอรีชื่อ include) - #include “ ชื่อเฮดเดอร์ไฟล์ ” คอมไพเลอร์จะทาการค้นหาเฮดเดอร์ไฟที่ระบุ จากไดเร็คทอรีเดียวกันกับ ไฟล์ source code นั้น แต้ถ้าไม่พบก็จะไปค้นหาไดเร็คทอรีที่ใช้เก็บ เฮดเดอร์ไฟล์โดยเฉพาะ 2. ส่วนของฟังก์ชั่นหลัก ฟังก์ชั่นหลักของภาษาซี คือ ฟังก์ชั่น main( ) ซึ่งโปรแกรมภาษาซีทุกโปรแกรมจะต้องมีฟังก์ชั่นนี้อยู่ ในโปรแกรมเสมอ จะเห็นได้จากชื่อฟังก์ชั่นคือ main แปลว่า “ หลัก ” ดังนั้น การเขียนโปรแกรมภาษซีจึง ขาดฟังก์ชั่นนี้ไปไม่ได้ โดยขอบเขตของฟังก์ชั่นจะถูกกาหนดด้วยเครื่องหมาย { และ } กล่าวคือ การทางาน ของฟังก์ชั่นจะเริ่มต้นที่เครื่องหมาย { และจะสิ้นสุดที่เครื่องหมาย } ฟังก์ชั่น main( ) สามารถเขียนใน รูปแบบของ void main(void) ก็ได้มีความหมายเหมือนกัน คือ หมายความว่า ฟังก์ชั่น main() จะไม่มี
  • 4. อาร์กิวเมนต์ (argument) คือไม่มีการรับค่าใด ๆ เข้ามาประมวลผลภายในฟังก์ชั่น และจะไม่มีการคืนค่าใด ๆ กลับออกไปจากฟังก์ชั่นด้วย 3. ส่วนรายละเอียดของโปรแกรม เป็นส่วนของการเขียนคาสั่ง เพื่อให้โปรแกรมทางานตามที่ได้ออกแบบไว้ คอมเมนต์ในภาษาซี คอมเมนต์ (comment) คือส่วนที่เป็นหมายเหตุของโปรแกรม มีไว้เพื่อให้ผู้เขียนโปรแกรมใส่ข้อความอธิบาย กากับลงไปใน source code ซึ่งคอมไพเลอร์จะข้ามาการแปลผลในส่วนที่เป็นคอมเมนต์นี้ คอมเมนต์ใน ภาษาซีมี 2 แบบคือ „ คอมเมนต์แบบบรรทัดเดียว ใช้เครื่องหมาย // „ คอมเมนต์แบบหลายบรรทัด ใช้เครื่องหมาย /* และ */ 3. มีนานุชควรสืบค้นตัวอย่างโปรแกรมภาษาซีจากเว็บไซต์ใด และมีรายละเอียดของตัวอย่างโปรแกรม ภาษาซีเป็นอย่างไร (1 คะแนน) ตอบ มีนานุชควรสืบค้นตัวอย่างโปรแกรมภาษาซีจากเว็บไซต์ http://blog.eduzones.com และมีรายละเอียด ดังนี้ ตัวอย่างของโปรแกรม การบวกค่าจานวนเต็ม 2 จานวนเข้าด้วยกัน แล้วแสดงผลลัพธ์ออกทางหน้าจอ การเขียนโปรแกรมเพื่อแก้ปัญหานี้ สามารถเขียนได้ดังนี้ #include
  • 5. void main() { int N1, N2, Sum; printf("please input an integer number : "); scanf("%d",&N1); printf("please input another integer number : "); scanf("%d",&N2); Sum = N1 + N2; printf("so, %d + %d = %d",N1,N2,Sum); } 4. นักเรียนช่วยอธิบายโปรแกรมทีละบรรทัดด้วยว่า โปรแกรมที่สืบค้นมานั้นเป็นส่วนประกอบใดของ โครงสร้างภาษาซี โดยใช้คอมเมนต์ (Comment) ในการเขียนคาอธิบาย (2 คะแนน) ตอบ #include //ส่วนหัวของโปรแกรม void main() //ฟังก์ชันหลัก { /*เริ่มต้นการเขียนโปรแกรมด้วยปากกาเปิด*/ int N1, N2, Sum; //ประกาศตัวแปร printf("please input an integer number : "); /*ส่วนรายละเอียดของโปรแกรม scanf("%d",&N1); printf("please input another integer number : "); scanf("%d",&N2);
  • 6. Sum = N1 + N2; printf("so, %d + %d = %d",N1,N2,Sum); */ } /*จบการเขียนโปรแกรมด้วยเครื่องหมายปากาปิด*/