ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ -...

20
กก 1 30252 !"#$ 1 กก 1 30252 !"#$% & ’(( &)"*+ % !"#$ % !"#$ ,% %"-.#/0 1972 & Dennis Ritchie <!=>(ก>??+ (Bell Lab) %.%#(!>> ’ก B <G>ก$ BCPL /J’’K>%L&!>,G ?M กN"-(G&L, C++ ?M C# "" &Q/ก<N B 1970 BCPL 1967 CPL 1963 ALGOL 1960 C 1972 % !"#$

Upload: dangkien

Post on 19-Aug-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 1

���� ก����� �������ก�� 1�������� � 30252

������ ����� !"�#�$���� ���%

�&�

�� �'(��(� ����&�)"�*���+

%�������� ���� �� � ������!"�#���$

%�������� ���� �� � ������!"�#���$

������,����� ���%

���%"�-��.#�/��0 1972 �&� Dennis Ritchie <��!���=�>�(�ก���>??+ (Bell Lab) %.�� ���%��#��(!��>>��'�ก ��� B <��� G>���ก$���� ��� BCPL

/��J''K>�� ���%L&!��>����������,���G��� � �?M�ก���N���"�-��(G���&L���,� ��� C++ �?M C# �"����"���&���������Q/�ก��<N����

B1970

BCPL1967

CPL1963

ALGOL1960

C1972

%�������� ���� �� � ������!"�#���$

Page 2: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 2

�K*��>�(�<��&&�&G��� ���%

1. �'� ���(�)*�+,-�ก�%.��$����$�/0�0%%�1�%� �ก�� (Portability)

2. ����0��(=� �"��� (Efficiency)

3. ���������CD�ก������ก���%%����/ (Modularity)

4. �������I���J+���� (Flexible Level)

5. �� ���������"O��$ O�$ (Pointer Operation)

6. ���S��O� ��O�ก��"��"$/Tก�/0 ��O�ก��"��"$D�U+� ก +��ก��

(Case Sensitivity)

%�������� ���� �� � ������!"�#���$

�M&�>�� ��� C ��� C ����'� ����0��%��� "��0 ���Y���)� +��Z�+��

D�U+�0Dก/[����ก�% �����J��$ � +กT���0��%���Y���)�(�)��/�ก�#0�/[��ก�%��U/�ก�#$�IO (Y�����[�D�*�[�+O�[����ก

%�������� ���� �� � ������!"�#���$

�M&�>�� ���

1. ����M&�>� � (High Level Language) �'� ���(�)Dก/[����ก�% �����J��$��ก(�)�J� (Y�D�[�����C(Y�����[�D� *�[�+�� �+� ��� C , BASIC, Pascal , FORTRAN �'� [�

2. ����M&�>(�N� (Low Level Language) �'� ���(�)Dก/[���ก�%��I)O��O�"�� O�$��ก ��I)O��O�"�� O�$�����C[�D��Y���)�D� �����-�*�[�+�� %.����''M�ก����?��,� ��������������L�GกYL&!

%�������� ���� �� � ������!"�#���$

Page 3: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 3

Compile �"�����?

����M&�>� � ��,� ����������

Source File L_?+ ���% .C

<����"��"+.#���

�?�กก��<N������ ��� C

Source File

Compile

Object File

C Library

Linker

Execute File

����� Compile �?!�'ML&!L_?+����กK? .obj

Link 'M��������� OBJ �!�ก�>L_?+<��ก�����ก/�!

'�กL?>���

L_?+ Execute (exe)

<����L�/�!���L&!

%�������� ���� �� � ������!"�#���$

��� !'�ก Text Editor �?M Compiler

Text Editor ��� ����ก��<�/�!�N����>��!���?M�ก!L Source Code

Compiler ��� ����ก�� / (����? ��� �&����L"�?��+'M<N� ก����?'�ก ����M&�>� � /�!��,� ����������

01000001A Compile

( �����K��+ --- > ���������� )

%�������� ���� �� � ������!"�#���$

IDE ��� �ML�

%�������� ���� �� � ������!"�#���$

IDE �+O����ก Integrated Development Environment �IO ��I)O��IO(�)�+��D�ก��"�f������ก�� ����0���J#��%� ��'� Text Editor �/0�� Compiler ��IO Interpreter ���O��+�[��ก�� �/0����)�OY���������0��ก +��Z �+� �Y���)� Compile, Run �ก ��O�+�� IDE �+� Editplus, Turbo C, Dev C++,Visual Studio �'� [�

Page 4: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 4

CodeBlocks ��,�����ก����M� <(IDE : Integrated Development Environment) �����K*��>�(���,� Text Editor � ? M � Compiler � �, �(����?�K&�N�����(G��m ���M��<n� �"/�ก��<N���� � ����������<��N���������M&�ก/�ก���������ก���?M�����>ก��<N����<��?�ก�?��

������ !'�ก����ก�� CodeBlocks

%�������� ���� �� � ������!"�#���$

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 1

- [�*�����$��/�����ก��(�) http://www.codeblocks.org/downloads/- ��ก��-�/IOก(�) Download the binary release

%�������� ���� �� � ������!"�#���$

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 2

- /IOก(�) CodeBlocks-16.01.mingw-setup.exe

%�������� ���� �� � ������!"�#���$

Page 5: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 5

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 3

- �O��ก���+�0����[� +����[� IO���ก��-�D�[��(Y�ก��%��(,ก*�[(�)��I)O��O�"�� O�$O� �O�

%�������� ���� �� � ������!"�#���$

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 4

- (Y�ก�� �� �-�����ก�����ก����%%�-/�/�ก(�)*o/$ �� �-� codeblocks-16.01 mingw-setup

%�������� ���� �� � ������!"�#���$

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 5 ��[� +������[O��������� [O���%��+ก�� �� �-� �/�ก/IOก(�) Next

%�������� ���� �� � ������!"�#���$

Page 6: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 6

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 6 ��[� +�������I)O�*ก��D�[�������ก�� �/�ก/IOก(�) I Agree

%�������� ���� �� � ������!"�#���$

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 7 ��[� +�������+����0กO%O�����ก�� �/�ก/IOก(�) I Agree

%�������� ���� �� � ������!"�#���$

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 8 ��[� +������ Y����+�(�)���กT%����ก�� �/�ก/IOก(�) Install

%�������� ���� �� � ������!"�#���$

Page 7: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 7

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 9 ��[� +�������-� O�#0 �� �-�����ก�� �O��ก���+

%�������� ���� �� � ������!"�#���$

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 10 ��[� +������[O���� q [O�ก���r�����ก��(��(���IO*�+s �/�ก

/IOก(�) No

%�������� ���� �� � ������!"�#���$

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 11 ��[� +���������/0O���ก�� �� �-�����ก���Y��T� �/�ก/IOก(�) Next

%�������� ���� �� � ������!"�#���$

Page 8: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 8

ก��(�&(�#�����ก�� CodeBlocks�#�(��<� 12 ��[� +������ก�� �� �-�����ก���Y��T� �/�ก/IOก(�) Finish

%�������� ���� �� � ������!"�#���$

%�������� ���� �� � ������!"�#���$

ก��/�!�������ก�� CodeBlocks�#�(��<� 1 ��%%�-/�/�ก(�)*O�O�����ก��

%�������� ���� �� � ������!"�#���$

Page 9: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 9

ก��/�!�������ก�� CodeBlocks�#�(��<� 2 ������[� +����)� [�ก��(Y����O�����ก�� CodeBlocks

%�������� ���� �� � ������!"�#���$

ก��/�!�������ก�� CodeBlocks�#�(��<� 3 ��)� [�ก����[��*o/$ ���S����*�(�)��� File => New =>File

%�������� ���� �� � ������!"�#���$

ก��/�!�������ก�� CodeBlocks�#�(��<� 4 /IOก(�) File => C/C++ �/[��/�ก(�) Go

%�������� ���� �� � ������!"�#���$

Page 10: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 10

ก��/�!�������ก�� CodeBlocks�#�(��<� 5 /IOก����%% �������ก�����/IOก�'� C �/[��/�ก(�) Next

%�������� ���� �� � ������!"�#���$

ก��/�!�������ก�� CodeBlocks�#�(��<� 6 �0%J�I)O*o/$����/0 Y����+�(�)�0���กT% ��ก��-��/�ก/IOก(�) Finish

%�������� ���� �� � ������!"�#���$

ก��/�!�������ก�� CodeBlocks�#�(��<� 7 ������[� +��ก��(Y����O�����ก��

�Q>���

"�#�<�<N����

��!�(G���'!��(���

%�������� ���� �� � ������!"�#���$

Page 11: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 11

ก�����>��&(����ก��/�����ก�� CodeBlocks

*�(�)��� Settings => Editor => General Settings => Font ��ก��-����% ���� ���������0��

%�������� ���� �� � ������!"�#���$

<&��>ก��<N����������ก�� CodeBlocks�#�(��<� 1 "��"$�J��Y���)� ���S�/�D�"I-�(�)ก��(Y����

%�������� ���� �� � ������!"�#���$

<&��>ก��<N����������ก�� CodeBlocks�#�(��<� 2 (Y�ก����/�J��Y���)� ���S�D�[�'� �����I)O����ก�� Compile S,)���

�����C(Y�*�[ 3 ��=� �����-

��=�(�) 1. *�(�)��� Build => Build ��=�(�) 2. ก����$/�� Ctrl + F9

Ctrl F9+

��=�(�) 3. ก�(�)�Jy� Build

%�������� ���� �� � ������!"�#���$

Page 12: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 12

<&��>ก��<N����������ก�� CodeBlocks�I)O(Y�ก�� Compile z+�� ����ก���0��[�[O����z+��(����[� +�� Build

messages S,)�D�[�����ก ��ก����[� IO��0 [O��'� 0 error , 0 warning

��ก����ก����[Oz��"/���0 [O� ����O%�J��Y���)��/0�ก[*D�[C�ก [O�

%�������� ���� �� � ������!"�#���$

<&��>ก��<N����������ก�� CodeBlocks�#�(��<� 3 (Y�ก������z//�"=$O�����ก�����ก�� Run S,)��������C(Y�*�[

3 ��=� �����-

��=�(�) 1. *�(�)��� Build => Run ��=�(�) 2. ก����$/�� Ctrl + F10

Ctrl F10+

��=�(�) 3. ก�(�)�Jy� Run

%�������� ���� �� � ������!"�#���$

<&��>ก��<N����������ก�� CodeBlocks�#�(��<� 4 �I)O(Y�ก�� Run ��T��/[��0���ก1��[� +������z//�"=$OOก��

%�������� ���� �� � ������!"�#���$

Page 13: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 13

<&��>ก��<N����������ก�� CodeBlocks������(K ��ก����)�D��+��J��Y���)�(�)"��"$C�ก [O��/[������C(Y�ก�� Compile

�/[� Run "I)O��z//�"=$*�[D�(��(� S,)��������C(Y�*�[ 3 ��=� �����-

��=�(�) 1. *�(�)��� Build => Build & Run ��=�(�) 2. ก����$/�� F9

F9

��=�(�) 3. ก�(�)�Jy� Build & Run

%�������� ���� �� � ������!"�#���$

������ !'�ก ��� C ก���Q�M

ก���������ก�� ��� C ��-� �0 [O���[��=�ก���/0�/�กD�ก���������ก�����ก+O� "��0C[�����[�/[���=�ก�� +��ZกT�0�+�� +Oก���������ก��

%�������� ���� �� � ������!"�#���$

������!���� ��� C#include <Header File> /*L_?+�G���������ก��*/�G����Mก�t <Declaration part> (�����/�G���<�/���&!�� ? /*ก����Mก�t(������>>�ก?>�?*/

main( ) /*����ก���?�ก*/{ /*�����(!�ก���������ก��*/ Variable declaration /* ก����Mก�t(������>>�?��? */

Program statement /* ��M����N����� */} /*'>ก���������ก��*/

����_J�ก+���() /*_J�ก+����G��*/{

Variable declaration /* ก����Mก�t(������>>�?��? */Program statement /* ��M����N����� */

}

1. �G�����������ก��1

2

3

2. _J�ก+����?�ก

3. _J�ก+����G��

%�������� ���� �� � ������!"�#���$

Page 14: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 14

#include <stdio.h>int main(){

printf("Hello World");return 0;

}

1. �G�����������ก��

# �IO ����"�S�SO�$(Preprocessor)

Include �IO *���(�o (Directive)

<stdio.h> �IO .��O�$*o/$ (Header file)

%�������� ���� �� � ������!"�#���$

�N��n�>������ก���"����(�����"��%��%��+ L&��Y�<_ (Preprocessor Directive) - (Jก����ก�� [O����+����-����0��)� [��[����I)O����� #- (�)���กD�[%+O��0�� 2 Directives �IO

#include D�[�Y����%���ก*o/$(�)����ก��D�[D�ก��(Y����ก+O��O�*"/$#define D�[�Y����%กY���������(�)D�[ก�%����ก��

�y&�&��+L_?+ (Header File ���� Processing Directive) � ��>>ก�����ก/�!1. #include <Header Name> �IO �0���ก*o/$D� directory "I-�~��O��O�*"/O�$2. #include {Header Name| �IO �0���ก*o/$D� directory ����ก�%*o/$����ก�� ��ก *�+"%�0*��� +OD� directory "I-�~��O��O�*"/O�$

%�������� ���� �� � ������!"�#���$

#include <stdio.h>int main(){

printf("Hello World");getch();return 0;

}

2. �+��o�����ก$�/�ก main( )

int �IO ��0 ([O��/(data type) (�)��%�+��+�ก/�%��(�)o��ก$��� main( )

main( ) �IO ก�����กD�[o��ก$����/�ก S,)� ��� C �0��)� [�(Y����(�)o�����ก$ main( ) �'�o��ก$�����กO��+��O ��ก*�+�� ����ก���0*�+(Y����

{ } �Y���)�ก��(Y���� +��Z �0O��+ ��D���I)O�������กก�

%�������� ���� �� � ������!"�#���$

Page 15: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 15

#include <stdio.h>int main(){

printf("Hello World");getch();return 0;

}

3. �+���Y���)�

printf ( ) �IO �Y���)�(�)D�[����[O��/ S,)�[O������IO �����D�Z (�)O��+ ��D� {.......| �0C�ก����OOก��(���O �" ����Y���)� printf ( ) �0O��+D�.��O�$*o/$ stdio.h

; �IO ก���%�Y���)�O� ��� C �I)O������Y���)�� +�/0�J��%�/[� [O��r��[�� (;) ��O

%�������� ���� �� � ������!"�#���$

#include <stdio.h>int main(){

printf("Hello World");getch();return 0;

}

getch() �IO �Y���)��O��%�+�D�Z ��ก(������"��"$ D�(�)��- "I)OกY����*�+D�[����ก���r���[� +��z//�"=$ �I)O����z//�"=$(�) [O�ก���/[�

%�������� ���� �� � ������!"�#���$

#include <stdio.h>int main(){

printf("Hello World"); getch();

return 0;}

Return 0 �IO �'��+��O�ก���+��+�[O��/ก/�%�I��I)Oo��ก$����%ก��(Y���� ����+�(�)�+�ก/�%*���-��0 [O��'�����[O��/ ��ก�%����[O��/O�o�����ก$��-��[�� S,)�D�(�)��-�+��+�ก/�%�IO 0 ก/�%*�(�)o��ก$��� main( )

%�������� ���� �� � ������!"�#���$

Page 16: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 16

ก���<�ก�N��n�>�� (Comment) /� ��� C

Comment ��IO �Y�O=�%������ก�� �'�ก������Y�O=�%��"I)OO=�%��ก��(Y����O�����ก�� S,)��+��D�O�����ก��(�)��*�[(Y�ก���(�ก�Y�O=�%�� (Comment) *�[��-��O�*"/O�$กT�0*�+��ก����0��/z/D��+��(�)��(Y�ก��กY����*�[ �Y����%ก���(�ก�Y�O=�%�� (Comment) �� 2 ����%% �����-

1. ก���(�ก�Y�O=�%���%%%��(������2. ก���(�ก�Y�O=�%���%%�/��%��(��

%�������� ���� �� � ������!"�#���$

� ��>>ก���<�ก�N��n�>�� (Comment) �>>>��<�&�&��

��=�ก���(�ก�Y�O=�%���%%%��(������ ��-����0 [O�"��"$��I)O����� // �/[� ���[��[O����D�Z S,)��O�*"/O�$��-��0*�+(Y�ก����0��/z/ก�%�J�[O����(�)O��+�/����I)O����� //

// �N��n�>��� ��>>

(����G����G� // This is Comment in C// I Love C Programming

%�������� ���� �� � ������!"�#���$

//This Program C by Jetavat

#include <stdio.h>int main()

{

printf("Welcome to C Programming \n"); // Show Text on Screenprintf("I Love C Programming");

getch();

return 0;}

�(�ก�Y�O=�%�� ��D�����ก��

%�������� ���� �� � ������!"�#���$

โปรแกรมการแทรกคําบรรยาย (Comment) แบบบรรทัดเดียว

Page 17: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 17

� ��>>ก���<�ก�N��n�>�� (Comment) �>>�?��>��<�&

��=�ก���(�ก�Y�O=�%���%%�/��%��(�� ��-����0 [O�"��"$[O����D�[O��+ ��D���I)O����� /*...*/ ����O�*"/O�$��-��0*�+(Y�ก����0��/z/ก�%�J�[O����(�)O��+ ��D���I)O����� /*...*/

/* �N��n�>��*/� ��>>

(����G����G� /* This is Comment in C I Love C Programming */

%�������� ���� �� � ������!"�#���$

/*

This Program C++Develop By Jetavat Sawaspanich

Date 28 June 2016

*/#include <stdio.h>

int main()

{printf("Welcome to C Programming \n");

printf("I Love C Programming");

getch();return 0;

}

�(�ก�Y�O=�%�� ��D�����ก��

%�������� ���� �� � ������!"�#���$

โปรแกรมการแทรกคําบรรยาย (Comment) แบบหลายบรรทัด

�N�����?!��'� �"/� ��� C

ก��/[���O �"D� ��� C ��-� ���0D�[�Y���)� Clear Screen S,)��'�o��ก$���(�)(Y���[�(�)D�ก��/[��[O��/D�O% O��������$�/0/I)O��O�$SO�$*�O��+(�)�J�S[��%�O��������$

system ("cls") ;

� ��>>

(����G����G� system ("cls") ; <= <N�ก��?!��!�'� �"

%�������� ���� �� � ������!"�#���$

Page 18: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 18

#include <stdio.h>

int main(){

printf("Press any key to continue" );

getch();system("cls");

printf("I Love C Programming");

getch();return 0;

}

%�������� ���� �� � ������!"�#���$

โปรแกรมล�างจอภาพ (Clear Screen)

���&��!���&"?�& (Type of Errors)

�Y����%[Oz��"/��(�)ก��,-���กก���������ก��D� ���S� �����C�%+�OOก�'� 3 �����[��ก�� �IO

1 [Oz��"/��(�)ก����ก*���ก�#$ (Syntax Errors)2 [Oz��"/��(�)ก����ก ��ก0����ก�� (Logic Errors)3 [Oz��"/��D�#0(�)�������ก�� (Runtime Errors)

%�������� ���� �� � ������!"�#���$

1. !���&"?�&<��ก�&'�กL���ก�*+ (Syntax Errors)[Oz��"/��(�)ก����ก*���ก�#$ (Syntax Errors) [Oz��"/��������- ก��

��กก��D�[*���ก�#$��IO����%% ���(�)z�� �+� �0ก��Y���)�z�� �(�(�)�0 [O�"��"$�Y���)� printf กT"��"$�'� print �'� [�

S,)��I)O�0(Y�ก����0��/z/�/[� ����/ ��� (Compiler) �0*�+��[��ก�Y���)����ก/+�� S,)�[Oz��"/����ก*���ก�#$��-� ����� ��� (Compiler) �����C ����O%"% �/0��[�[Oz��"/��(�)ก��,-�D�[(��%*�[

%�������� ���� �� � ������!"�#���$

Page 19: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 19

#include <stdio.h>

int main(){

print("Welcome to C Programming \n");

print("I Love C Programming");getch();

return 0;

}

%�������� ���� �� � ������!"�#���$

โปรแกรมข�อผิดพลาดที่เกิดจากไวยากรณ. (Syntax Errors)

2. !���&"?�&<��ก�&'�ก(��กM����ก�� (Logic Errors)

[Oz��"/��(�)ก����ก ��ก0����ก��(Logic Errors) [Oz��"/��������- ก����ก ��z�[�������ก��O� �+�ก��D�[ ��ก0(�)z��"/�� ��IOก����[���� ��Y���#(�)z�� �+�z/D�[z//�"=$z��"/�� �+� ก�����+��/�)�O� ��/�O��Y���� C[���ก��(Y�ก����[���� ��IO Average = Num1 + Num2 / 2 z//�"=$(�)*�[�0z�� "��0C[�����(�)/Y���%�����Y���UO���I)O����� ��"��$��-�0(Y�ก�����ก+O��/[��+O�%�ก(��/�� C[�����ก�0�ก[*D�[C�ก [O��0 [O��ก[*�'� Average = (Num1 + Num2) / 2

S,)�[Oz��"/���%%��- ����/ ��� (Compiler) �0 ����O%*�+"% �����-�z�[�������ก���,� [O���ก�� ����O%�I)O�*��IO�� �D�[C�ก [O�ก+O�(Jก���-�

%�������� ���� �� � ������!"�#���$

#include <stdio.h>

int main(){

int Num1=10,Num2=20;

float Average;Average=Num1 + Num2 / 2;

printf("Avaerage = %.2f", Average);

getch();return 0;

}

%�������� ���� �� � ������!"�#���$

โปรแกรมข�อผิดพลาดที่เกิดจากตรรกะโปรแกรม (Logic Errors)

Page 20: ก ก 1 30252 ˝˛˚ ˜ ! ˝# $ ˚ - jetavat.comjetavat.com/classroom_online/images/Com30252/Lesson/Lesson1.pdf · ก 1 30252 ... FORTRAN ’ [ 2. M & >(˛N (Low Level Language)

������� ก����� �������ก�� 1 �������� �30252

��� ���� �� � ������!"�#���$ 20

[Oz��"/��D�#0(�)�������ก�� (Runtime Errors) [Oz��"/��������-�0"%*�[D� O�(�)��I)O�กY�/��(Y�����/[�ก����กก����� ��/�[������$ ( 0 ) �+� x = 5 �/0 y = 0 ��ก��-���ก����)�D�[�Y���#�+�O� x ����[�� y ����ก���0��[� IO� Runtime Errors "��0ก����กก������[������$ ( 0 ) ��)�O�

S,)�[Oz��"/���%%��- ����/ ��� (Compiler) �0�����C��/ ��� (Compile) z+��*�*�[ � +�0*�+�����C����z//�"=$*�[

3. !���&"?�&/�*M<��������ก�� (Runtime Errors)

%�������� ���� �� � ������!"�#���$

#include <stdio.h>

int main(){

int X=5,Y=0;

float Result;Result=X / Y;

printf("Result = %.2f", Result);

getch();return 0;

}

%�������� ���� �� � ������!"�#���$

โปรแกรมข�อผิดพลาดในขณะที่รันโปรแกรม (Runtime Errors)

�'<�+�J��������& �K&<� 1

1. '��n�>��Q.���M��(��� ��� C ��"������ ?

2. '��n�>��Q.� ����M&�>� � �?M ����M&�>(�N� (G��ก����G��L� ?

3. '��n�>���?�กก��<N������ ��� C ��#�(����G��L� ?

4. '�>�ก���������� Text Editor, Compiler �?M IDE ����ML� ?

5. ������!�� ��� C �ก��G�� �ML�>!�� '��n�>�� ?

%�������� ���� �� � ������!"�#���$