SlideShare a Scribd company logo
1 of 40
ทบทวนการเขียนโปรแกรมด้วยภาษาซี ณัฐวุฒิ ปอโนนสูง กลุ่มสาระฯการงานอาชีพและเทคโนโลยี  โรงเรียนศรีสะเกษวิทยาลัย
เนื้อหา ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
เริ่มต้นใช้งาน  Dev-C++ ,[object Object],[object Object],[object Object],[object Object]
เริ่มต้นใช้งาน  Dev-C++ ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ดีบักโปรแกรมด้วย  Dev-C++ ,[object Object],[object Object],[object Object]
ตัวอย่างโปรแกรมภาษาซี #include  <stdio.h> int  main() { int  a, b, sum; printf(&quot;Enter A: &quot;); scanf(&quot;%d&quot;, &a); printf(&quot;Enter B: &quot;); scanf(&quot;%d&quot;, &b); sum = a+b; printf(&quot;Sum = %d&quot;, sum); return  0; } คืนค่า  0  เพื่อระบุว่าโปรแกรมจบการทำงานโดยไม่มีข้อผิดพลาด อ่านไฟล์  stdio.h  เพื่อเอาฟังก์ชันมาตรฐานมาใช้ ฟังก์ชัน  main  ระบุจุดเริ่มต้นของโปรแกรม คืนค่ากลับเป็น  int ประกาศตัวแปรแบบ  int  สามตัวคือ  a, b  และ  sum ฟังก์ชันมาตรฐาน  printf()  ใช้พิมพ์ข้อความออกทางหน้าจอ ฟังก์ชันมาตรฐาน  scanf()  ใช้รับอินพุทจากแป้นพิมพ์
โครงสร้างหน่วยความจำ 1  ช่อง  = 1   ไบต์  ( 8  บิต ) ตำแหน่งที่อยู่ (address) ข้อมูลที่เก็บ (data) 0000 32 0001 67 0002 255 0003 0 0004 121 : :
[object Object],[object Object],ตัวแปร   (Variable) short  a, b, sum; a = 10; b = 5; sum = a+b; b   มีค่า  5  ( อ้างถึง ค่า ) &b   มีค่า  1002  ( อ้างถึง ตำแหน่ง ) ตำแหน่ง ค่า : : 1000 2 1001 30 1002 211 1003 5 1005 23 : : 1004 8 10 0 5 0 0 15 a b sum
ชนิดข้อมูลพื้นฐาน 255 0 1 unsigned char 18,446,744,073,709,551,615 0 8 unsigned long long +9,223,372,036,854,775,807 − 9,223,372,036,854,775,808 8 long long +2,147,483,647 -2,147,483,648 4 long +32,767  หรือ  +2,147,483,647 -32,768  หรือ  -2,147,483,648 2  หรือ  4 int 0 0 0 -32,768 -128 ค่าต่ำสุด 4,294,967,295 65,535  หรือ  4,294,967,295 65,535 +32,767 +127 ค่าสูงสุด 1 char 4 unsigned long 2  หรือ  4 unsigned int 2 unsigned short 2 short ขนาด ( ไบต์ ) การประกาศ
ชนิดข้อมูลอื่น ๆ ,[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],ตัวแปรแบบตัวชี้   (Pointer) short  a = 57; short  *p; p = &a; *p = 78; p   มีค่า  20  ( ค่าของ  p ) &p   มีค่า  22  ( ตำแหน่งของ  p ) *p   มีค่า  78  ( ค่าในตำแหน่งที่  p   ชี้อยู่ ) ตำแหน่ง ค่า : : 0020 2 0021 30 0022 211 0023 5 0025 23 : : 0024 8 57 0 20 0 p 78 0 a
อาร์เรย์และสตริง ,[object Object],[object Object],short  arr[3]; arr[0] = 50; arr[2] = 89; arr   มีค่า  20 arr[0]   มีค่า  50 &arr   มีค่า  20 *arr   มีค่า  50 23 8 ตำแหน่ง ค่า : : 0020 2 0021 30 0022 211 0023 5 0027 12 : : 0026 33 0025 0024 50 0 89 0 arr
ข้อมูลประเภทสายอักขระ  ( สตริง ) ,[object Object],char  s[] = &quot;Hello&quot;; printf(&quot;%c %c %c&quot;, s[0], s[1], s[2]); H e l ผลลัพธ์ :
สัญพจน์  (Literal) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
การรับ / แสดงผล ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
การแสดงผลข้อมูล ,[object Object],[object Object],char  c = 65; printf(&quot;c (as a number) = %d&quot;, c); printf(&quot;c (as a character) = %c&quot;, c); หน่วยความจำ : 2 30 65 5 23 : 8 c c (as a number) = 65 c (as a character) = A ผลลัพธ์ :
%format  ใน  scanf  และ  printf %s char array[] สตริง %c char อักขระโดด %lf double %f float จำนวนมีทศนิยม %llu unsigned long long %lu unsigned long %u unsigned int %lld long long %ld long %d int จำนวนเต็ม %format ชนิดตัวแปร ชนิดข้อมูล
ตัวอย่างการใช้  scanf char  name[20]; int  age; printf(&quot;Enter your name and age: &quot;); scanf(&quot;%s %d&quot;, name, &age); printf(&quot;Hello %s.  You are %d years old.&quot;, name, age); Enter your name and age:  Tony 38 Hello Tony.  You are 38 years old. ผลลัพธ์ :
การไหลของโปรแกรม ,[object Object],START END Statement โปรแกรมที่มีคำสั่งเดียว โปรแกรมที่มีหลายคำสั่ง Statement 1 Statement 2 Statement n END START Statement 3
การควบคุมการไหลของโปรแกรม ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
โครงสร้าง  if ,[object Object],[object Object],[object Object],if ( condition )  { statement1; : statementN; } C Syntax START END Statement condition true false Statement Flowchart
โครงสร้าง  if…else if ( condition ) {  statement t1 ; statement t2 ; } else { statement f1 ; statement f2 ;  } C Syntax Flowchart START END Statement f1 condition true false Statement t1 Statement f2 Statement t2
โครงสร้าง   if   แบบหลายเงื่อนไข ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],false Action1; x==1 Action2; x==2 Action3; x==3 Action4; x==4 true true true true false false false Default_Action;
โครงสร้าง   switch-case ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],false Action1; x==1 Action2; x==2 Action3; x==3 Action4; x==4 true true true true false false false Default_Action;
โครงสร้าง  while   ลูป ,[object Object],condition while ( condition )  { stmt1 ; stmt2 ; : stmtN ; } END START true Statement Statement false
โครงสร้าง  do…while   ลูป ,[object Object],[object Object],END condition do   { stmt1 ; stmt2 ; : stmtN ; }  while  ( condition ); false START Statement 1 Statement N true
ลูปวนนับ  ( Counting Loop) ,[object Object],[object Object],int  i, sum = 0; i = 1; while  (i <= 10) { sum = sum + i; i = i + 1; } printf(&quot;Sum = %d&quot;, sum); ตัวแปรที่ใช้นับ ส่วนกำหนดค่าเริ่มต้น การปรับค่าตัวนับ เงื่อนไขของตัวนับ คำสั่งที่ถูกทำซ้ำ
โครงสร้าง  for  ลูป ,[object Object],[object Object],[object Object],[object Object],[object Object],for ( init_stmt ;  condition ;  update_stmt ) { statement1 ; statement2 ; : statementN ; }
การทำงานของ  for  ลูป false update_stmt for ( init_stmt ;  condition ;  update_stmt ) { statement1 ; statement2 ; : statementN ; } START END condition true Statement1 StatementN init_stmt
โปรแกรมย่อย  (Subroutine) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ชนิดของฟังก์ชัน ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ตัวอย่างฟังก์ชันมาตรฐาน rand ,  atoi ,  atof stdlib.h อื่น ๆ strlen ,  strcpy ,  strcmp string.h จัดการกับสตริง isalpha ,  isdigit ,  islower ,  isupper ctype.h แยกประเภทข้อมูลอักขระ sin ,  cos ,  exp ,  pow math.h คณิตศาสตร์ scanf ,  printf ,  gets ,  puts stdio.h จัดการอินพุท / เอาท์พุท ตัวอย่างฟังก์ชัน เฮดเดอร์ไฟล์ กลุ่มฟังก์ชัน
ฟังก์ชันที่ผู้ใช้กำหนดเอง ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],void  say_hi(char *name) { printf(&quot;Hi, %s&quot;, name); } int  max(int a, int b) { if (a > b) return a; else return b; }
การไหลของโปรแกรมเมื่อใช้ฟังก์ชัน int  incr(int i) { int  j; j = i + 1; return  j; } int  main()  { int  k, m = 4; k = incr(m); printf (&quot;k = %d, m = %d&quot;, k, m); return  0; }
ขั้นตอนวิธีกับการโปรแกรม ,[object Object],[object Object]
ตัวอย่าง ,[object Object],Enter N:  3 * ** *** Enter N:  5 * ** *** **** *****
ตัวอย่าง ,[object Object],[object Object],หาตัวน้อยที่สุด สลับที่มาไว้ด้านหน้า ทำซ้ำ   เฉพาะกับส่วนที่เหลือ 1 2 3 4 5 2 3 4 5 1 1 2 3 4 5 2 1 2 3 4 5 1 4 2
ข้อผิดพลาดที่พบบ่อย #include  <stdio.h> int  main () { int  i; scanf(&quot;%d&quot;, i); if  (i = 0) puts(&quot;false&quot;); else puts(&quot;true&quot;); return  0; } ส่งค่า  i  ให้   scanf  แทนที่จะส่งตำแหน่ง ใช้คำสั่งกำหนดค่า  (=)  แทนการเปรียบเทียบ  (==)
ข้อผิดพลาดที่พบบ่อย #include  <stdio.h> int  main () { char  s[10]; printf(&quot;Enter password: &quot;); scanf(&quot;%s&quot;, s); if  (s == &quot;pass&quot;) puts(&quot;Correct password&quot;); else puts(&quot;Incorrect password&quot;); return  0; } ใช้  ==  เปรียบเทียบสตริงไม่ได้ ใช้ฟังก์ชัน  strcmp()  แทน
เอกสารอ้างอิง ,[object Object],[object Object]

More Related Content

What's hot

บทที่ 6 อาร์เรย์
บทที่ 6 อาร์เรย์บทที่ 6 อาร์เรย์
บทที่ 6 อาร์เรย์Theeravaj Tum
 
Java Programming: โครงสร้างควบคุม
Java Programming: โครงสร้างควบคุมJava Programming: โครงสร้างควบคุม
Java Programming: โครงสร้างควบคุมThanachart Numnonda
 
การเขียนคำสั่งควบคุมแบบมีทางเลือก.
การเขียนคำสั่งควบคุมแบบมีทางเลือก.การเขียนคำสั่งควบคุมแบบมีทางเลือก.
การเขียนคำสั่งควบคุมแบบมีทางเลือก.Mink Kamolwan
 
เครื่องหมายและการดำเนินการในภาษาซี
เครื่องหมายและการดำเนินการในภาษาซีเครื่องหมายและการดำเนินการในภาษาซี
เครื่องหมายและการดำเนินการในภาษาซีเทวัญ ภูพานทอง
 
Java Programming: คลาสอินพุตและเอาต์พุต
Java Programming: คลาสอินพุตและเอาต์พุตJava Programming: คลาสอินพุตและเอาต์พุต
Java Programming: คลาสอินพุตและเอาต์พุตThanachart Numnonda
 
Java Programming [12/12] : Thread
Java Programming [12/12] : ThreadJava Programming [12/12] : Thread
Java Programming [12/12] : ThreadIMC Institute
 
Java Programming: หลักการเชิงอ็อบเจกต์
Java Programming: หลักการเชิงอ็อบเจกต์Java Programming: หลักการเชิงอ็อบเจกต์
Java Programming: หลักการเชิงอ็อบเจกต์Thanachart Numnonda
 
การประกาศตัวแปรในภาษาซี
การประกาศตัวแปรในภาษาซีการประกาศตัวแปรในภาษาซี
การประกาศตัวแปรในภาษาซีmycomc55
 
59170259 ผลคุณี
59170259 ผลคุณี59170259 ผลคุณี
59170259 ผลคุณีBeam Suna
 
59170249 ธิดารัตน์
59170249 ธิดารัตน์59170249 ธิดารัตน์
59170249 ธิดารัตน์Beam Suna
 

What's hot (19)

บทที่ 6 อาร์เรย์
บทที่ 6 อาร์เรย์บทที่ 6 อาร์เรย์
บทที่ 6 อาร์เรย์
 
7 2โครงสร้าง
7 2โครงสร้าง7 2โครงสร้าง
7 2โครงสร้าง
 
Java Programming: โครงสร้างควบคุม
Java Programming: โครงสร้างควบคุมJava Programming: โครงสร้างควบคุม
Java Programming: โครงสร้างควบคุม
 
02 basic
02 basic02 basic
02 basic
 
การเขียนคำสั่งควบคุมแบบมีทางเลือก.
การเขียนคำสั่งควบคุมแบบมีทางเลือก.การเขียนคำสั่งควบคุมแบบมีทางเลือก.
การเขียนคำสั่งควบคุมแบบมีทางเลือก.
 
Know3 4
Know3 4Know3 4
Know3 4
 
Unit8
Unit8Unit8
Unit8
 
เครื่องหมายและการดำเนินการในภาษาซี
เครื่องหมายและการดำเนินการในภาษาซีเครื่องหมายและการดำเนินการในภาษาซี
เครื่องหมายและการดำเนินการในภาษาซี
 
Unit7
Unit7Unit7
Unit7
 
Java Programming: คลาสอินพุตและเอาต์พุต
Java Programming: คลาสอินพุตและเอาต์พุตJava Programming: คลาสอินพุตและเอาต์พุต
Java Programming: คลาสอินพุตและเอาต์พุต
 
Java Programming [12/12] : Thread
Java Programming [12/12] : ThreadJava Programming [12/12] : Thread
Java Programming [12/12] : Thread
 
C slide
C slideC slide
C slide
 
Java Programming: หลักการเชิงอ็อบเจกต์
Java Programming: หลักการเชิงอ็อบเจกต์Java Programming: หลักการเชิงอ็อบเจกต์
Java Programming: หลักการเชิงอ็อบเจกต์
 
การประกาศตัวแปรในภาษาซี
การประกาศตัวแปรในภาษาซีการประกาศตัวแปรในภาษาซี
การประกาศตัวแปรในภาษาซี
 
Unit9
Unit9Unit9
Unit9
 
59170259 ผลคุณี
59170259 ผลคุณี59170259 ผลคุณี
59170259 ผลคุณี
 
3.5 การแสดงผลและการรับข้อมูล
3.5 การแสดงผลและการรับข้อมูล3.5 การแสดงผลและการรับข้อมูล
3.5 การแสดงผลและการรับข้อมูล
 
59170249 ธิดารัตน์
59170249 ธิดารัตน์59170249 ธิดารัตน์
59170249 ธิดารัตน์
 
4 1
4 14 1
4 1
 

Similar to C lang

Computer programming
Computer programmingComputer programming
Computer programmingJariyaa
 
Slide unit1 พื้นฐานภาษาซี
Slide unit1  พื้นฐานภาษาซีSlide unit1  พื้นฐานภาษาซี
Slide unit1 พื้นฐานภาษาซีNoonid Maehongson
 
บทที่ 5 ข้อมูลชนิดอาร์เรย์และสตริง 6.1
บทที่  5 ข้อมูลชนิดอาร์เรย์และสตริง 6.1บทที่  5 ข้อมูลชนิดอาร์เรย์และสตริง 6.1
บทที่ 5 ข้อมูลชนิดอาร์เรย์และสตริง 6.1Little Tukta Lita
 
การแสดงผลและการรับข้อมูล
การแสดงผลและการรับข้อมูลการแสดงผลและการรับข้อมูล
การแสดงผลและการรับข้อมูลkorn27122540
 
C Programming
C ProgrammingC Programming
C ProgrammingWarawut
 
3.ประเภทของข้อมูลและตัวดำเนินการ
3.ประเภทของข้อมูลและตัวดำเนินการ3.ประเภทของข้อมูลและตัวดำเนินการ
3.ประเภทของข้อมูลและตัวดำเนินการmansuang1978
 
59170065 พัชริกา
59170065 พัชริกา59170065 พัชริกา
59170065 พัชริกาBeam Suna
 
คำสั่งรับข้อมูลจากคีย์บอร์ด
คำสั่งรับข้อมูลจากคีย์บอร์ดคำสั่งรับข้อมูลจากคีย์บอร์ด
คำสั่งรับข้อมูลจากคีย์บอร์ดเทวัญ ภูพานทอง
 
7 pointer day10
7  pointer day107  pointer day10
7 pointer day10xuou888
 
คอมพิวเตอร์โอลิมปิก
คอมพิวเตอร์โอลิมปิกคอมพิวเตอร์โอลิมปิก
คอมพิวเตอร์โอลิมปิกSumalee Sonamthiang
 

Similar to C lang (20)

C language
C languageC language
C language
 
Computer programming
Computer programmingComputer programming
Computer programming
 
12
1212
12
 
Introduction toc
Introduction tocIntroduction toc
Introduction toc
 
Python101
Python101Python101
Python101
 
Chapter 02 Flowchart
Chapter 02 FlowchartChapter 02 Flowchart
Chapter 02 Flowchart
 
05 Loops
05  Loops05  Loops
05 Loops
 
Slide unit1 พื้นฐานภาษาซี
Slide unit1  พื้นฐานภาษาซีSlide unit1  พื้นฐานภาษาซี
Slide unit1 พื้นฐานภาษาซี
 
207
207207
207
 
บทที่ 5 ข้อมูลชนิดอาร์เรย์และสตริง 6.1
บทที่  5 ข้อมูลชนิดอาร์เรย์และสตริง 6.1บทที่  5 ข้อมูลชนิดอาร์เรย์และสตริง 6.1
บทที่ 5 ข้อมูลชนิดอาร์เรย์และสตริง 6.1
 
การแสดงผลและการรับข้อมูล
การแสดงผลและการรับข้อมูลการแสดงผลและการรับข้อมูล
การแสดงผลและการรับข้อมูล
 
Computer Programming 3
Computer Programming 3 Computer Programming 3
Computer Programming 3
 
C Programming
C ProgrammingC Programming
C Programming
 
3.ประเภทของข้อมูลและตัวดำเนินการ
3.ประเภทของข้อมูลและตัวดำเนินการ3.ประเภทของข้อมูลและตัวดำเนินการ
3.ประเภทของข้อมูลและตัวดำเนินการ
 
Variable Constant Math
Variable Constant MathVariable Constant Math
Variable Constant Math
 
59170065 พัชริกา
59170065 พัชริกา59170065 พัชริกา
59170065 พัชริกา
 
คำสั่งรับข้อมูลจากคีย์บอร์ด
คำสั่งรับข้อมูลจากคีย์บอร์ดคำสั่งรับข้อมูลจากคีย์บอร์ด
คำสั่งรับข้อมูลจากคีย์บอร์ด
 
05 loops
05 loops05 loops
05 loops
 
7 pointer day10
7  pointer day107  pointer day10
7 pointer day10
 
คอมพิวเตอร์โอลิมปิก
คอมพิวเตอร์โอลิมปิกคอมพิวเตอร์โอลิมปิก
คอมพิวเตอร์โอลิมปิก
 

C lang

  • 1. ทบทวนการเขียนโปรแกรมด้วยภาษาซี ณัฐวุฒิ ปอโนนสูง กลุ่มสาระฯการงานอาชีพและเทคโนโลยี โรงเรียนศรีสะเกษวิทยาลัย
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. ตัวอย่างโปรแกรมภาษาซี #include <stdio.h> int main() { int a, b, sum; printf(&quot;Enter A: &quot;); scanf(&quot;%d&quot;, &a); printf(&quot;Enter B: &quot;); scanf(&quot;%d&quot;, &b); sum = a+b; printf(&quot;Sum = %d&quot;, sum); return 0; } คืนค่า 0 เพื่อระบุว่าโปรแกรมจบการทำงานโดยไม่มีข้อผิดพลาด อ่านไฟล์ stdio.h เพื่อเอาฟังก์ชันมาตรฐานมาใช้ ฟังก์ชัน main ระบุจุดเริ่มต้นของโปรแกรม คืนค่ากลับเป็น int ประกาศตัวแปรแบบ int สามตัวคือ a, b และ sum ฟังก์ชันมาตรฐาน printf() ใช้พิมพ์ข้อความออกทางหน้าจอ ฟังก์ชันมาตรฐาน scanf() ใช้รับอินพุทจากแป้นพิมพ์
  • 7. โครงสร้างหน่วยความจำ 1 ช่อง = 1 ไบต์ ( 8 บิต ) ตำแหน่งที่อยู่ (address) ข้อมูลที่เก็บ (data) 0000 32 0001 67 0002 255 0003 0 0004 121 : :
  • 8.
  • 9. ชนิดข้อมูลพื้นฐาน 255 0 1 unsigned char 18,446,744,073,709,551,615 0 8 unsigned long long +9,223,372,036,854,775,807 − 9,223,372,036,854,775,808 8 long long +2,147,483,647 -2,147,483,648 4 long +32,767 หรือ +2,147,483,647 -32,768 หรือ -2,147,483,648 2 หรือ 4 int 0 0 0 -32,768 -128 ค่าต่ำสุด 4,294,967,295 65,535 หรือ 4,294,967,295 65,535 +32,767 +127 ค่าสูงสุด 1 char 4 unsigned long 2 หรือ 4 unsigned int 2 unsigned short 2 short ขนาด ( ไบต์ ) การประกาศ
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. %format ใน scanf และ printf %s char array[] สตริง %c char อักขระโดด %lf double %f float จำนวนมีทศนิยม %llu unsigned long long %lu unsigned long %u unsigned int %lld long long %ld long %d int จำนวนเต็ม %format ชนิดตัวแปร ชนิดข้อมูล
  • 18. ตัวอย่างการใช้ scanf char name[20]; int age; printf(&quot;Enter your name and age: &quot;); scanf(&quot;%s %d&quot;, name, &age); printf(&quot;Hello %s. You are %d years old.&quot;, name, age); Enter your name and age: Tony 38 Hello Tony. You are 38 years old. ผลลัพธ์ :
  • 19.
  • 20.
  • 21.
  • 22. โครงสร้าง if…else if ( condition ) { statement t1 ; statement t2 ; } else { statement f1 ; statement f2 ; } C Syntax Flowchart START END Statement f1 condition true false Statement t1 Statement f2 Statement t2
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. การทำงานของ for ลูป false update_stmt for ( init_stmt ; condition ; update_stmt ) { statement1 ; statement2 ; : statementN ; } START END condition true Statement1 StatementN init_stmt
  • 30.
  • 31.
  • 32. ตัวอย่างฟังก์ชันมาตรฐาน rand , atoi , atof stdlib.h อื่น ๆ strlen , strcpy , strcmp string.h จัดการกับสตริง isalpha , isdigit , islower , isupper ctype.h แยกประเภทข้อมูลอักขระ sin , cos , exp , pow math.h คณิตศาสตร์ scanf , printf , gets , puts stdio.h จัดการอินพุท / เอาท์พุท ตัวอย่างฟังก์ชัน เฮดเดอร์ไฟล์ กลุ่มฟังก์ชัน
  • 33.
  • 34. การไหลของโปรแกรมเมื่อใช้ฟังก์ชัน int incr(int i) { int j; j = i + 1; return j; } int main() { int k, m = 4; k = incr(m); printf (&quot;k = %d, m = %d&quot;, k, m); return 0; }
  • 35.
  • 36.
  • 37.
  • 38. ข้อผิดพลาดที่พบบ่อย #include <stdio.h> int main () { int i; scanf(&quot;%d&quot;, i); if (i = 0) puts(&quot;false&quot;); else puts(&quot;true&quot;); return 0; } ส่งค่า i ให้ scanf แทนที่จะส่งตำแหน่ง ใช้คำสั่งกำหนดค่า (=) แทนการเปรียบเทียบ (==)
  • 39. ข้อผิดพลาดที่พบบ่อย #include <stdio.h> int main () { char s[10]; printf(&quot;Enter password: &quot;); scanf(&quot;%s&quot;, s); if (s == &quot;pass&quot;) puts(&quot;Correct password&quot;); else puts(&quot;Incorrect password&quot;); return 0; } ใช้ == เปรียบเทียบสตริงไม่ได้ ใช้ฟังก์ชัน strcmp() แทน
  • 40.