1 includefile h type functionnametype type variable int
โครงสรางโปรแกรมภาษาซ (1) #include<file. h> ��������� type function_name(type); ��������� type variable; �������� int main() { type variable; �������� statement-1; ������. . . ������ statement-n; return 0; ������ } type function_name(type variable) { statement-1; . . . ������ statement-n; return(var); } 3
ตวอยางการใชงานคำสง printf ทถกตอง #include<stdio. h> int main() { printf ("Hello World!"); return 0; } Hello World! 13
ตวอยางการใชงานคำสง printf หลายๆคำสง #include<stdio. h> #include<conio. h> int main() { printf ("Hello World!"); printf ("This is my first Program. "); printf ("I am a programmer. "); return 0; } Hello World!This is my first Program. I am a programmer. 16
ตวอยางการใชงานคำสง printf โดยใชคารหส ASCII #include<stdio. h> int main() { printf ("Hello World!n"); printf ("This is my first Program. "); printf ("nt. I'm a programmer. "); return 0; } Hello World! This is my first Program. I'm a programmer. 18
ตวอยางการใชงานคำสง printf แสดงผลขอมล #include<stdio. h> int main() { printf ("My name is : %sn", "Kmitl"); printf ("My point : %dn", 10+40+49); printf ("Grade : %cn", 'A'); printf ("GPA : %f", 3. 99); return 0; } My name is : Kmitl My point : 99 Grade : A GPA : 3. 990000 21
ตวอยางการใชงานคำสง printf แสดงผลขอมลหลายตว -1 #include<stdio. h> int main() { printf ("Age = %d, GPA = %fn", 17, 3. 75); printf ("Programming: %fn. Mechanics: %f", 4. 0, 3. 5); return 0; } Age = 17, GPA = 3. 750000 Programming: 4. 000000 Mechanics: 3. 5000000 24
ตวอยางการใชงานคำสง printf แสดงผลขอมลหลายตว -2 #include<stdio. h> int main() { printf ("Subject : %s(%d)n", "Programming", 2552); printf ("Point : %dn. Grade : %c", 99, 'A'); return 0; } Subject : Programming(2552) Point : 99 Grade : A 25
ตวอยางการใชงานคำสง printf โดยมการกำหนดรปแบบ 1 #include<stdio. h> int main() { printf ("12345678901234567890"); printf ("n%20 d*", 46); printf ("n%-20 d*", 46); printf ("n%3 d*", 2550); return 0; } 12345678901234567890 46* 46* 2550* 27
ตวอยางการใชงานคำสง printf โดยมการกำหนดรปแบบ 2 #include <stdio. h> int main() { printf ("12345678901234567890"); printf ("n%20 c*", 'c'); printf ("n%-20 c*", 'c'); printf ("n%10 s*", "Pro"); printf ("n%10 s*", "Programming"); return 0; } 12345678901234567890 c* c * Programming* 28
ตวอยางการใชงานคำสง printf โดยมการกำหนดรปแบบ 3 printf printf ("12345678901234567890"); ("n%20 s*", "programming"); ("n%-20 s*", "programming"); ("n%. 3 s*", "programming"); ("n%20. 3 s*", "programming"); ("n%-20. 3 s*", "programming"); 12345678901234567890 programming* programming * pro* pro *_ 30
ตวอยางการใชงานคำสง printf โดยมการกำหนดรปแบบ 4 printf printf ("12345678901234567890"); ("n%20 f*", 1234. 56789); ("n%-20 f*", 1234. 56789); ("n%. 3 f*", 1234. 56789); ("n%20. 3 f*", 1234. 56789); ("n%-20. 3 f*", 1234. 56789); 12345678901234567890 1234. 567890* 1234. 567890 * 1234. 568* 1234. 568 *_ 31
รปแบบคำอธบายโปรแกรม /* Comment Sentence 1 Comment Sentence 2. . . Comment Sentence n */ /* Comment Sentence */ // Comment Sentence 33
คำถามทายบท 1. แสดงผลของโปรแกรมตอไปน #include<stdio. h> int main() { /* float radius, pi, area; pi = 22/7; // pi = 3. 14; printf ("Enter Radius of Circular : "); scanf ("%f", &radius); area = pi * radius; */ printf (“Programming Language”, 2008); return 0; } 37
- Slides: 38