Upload
nattapon
View
1.897
Download
7
Embed Size (px)
DESCRIPTION
Citation preview
���ก���� ���ก���� PrintfPrintf(); (); ��� ��� ScanfScanf();();��� ��� ScanfScanf();();
�������������� !"�#$ก%&'�(�&ก&� �)&�*กก&+�*,�-'� .�/ !0�
�������������� !"�#$ก%&'�(�&ก&� �)&�*กก&+�*,�-'� .�/ !0�
ก��������ก����� ����ก��������ก����� ����
printf ����������������scanf ������ ������ก"#$%���%�
���� printf � � scanf ��ก�ก���������� � stdio.h $������ก����%&�'��(�ก�%�� printf � � scanf )&�� �%&*+',�-�
#include<stdio.h>
���ก���� ���ก���� printfprintf()()
printf() 012�3���ก'2�%&�'�$���1�1. ���1�2�#��3���ก�������
printf(5 ��"6��7); �%�� printf(4Hello world9);�%�� printf(4Hello world9);
2. ����#��3���ก�������printf(5��3���ก�������7, <=��<%);�%�� printf(4My age is %d\n9, myAge);
��3���ก���������3���ก�������format code ������
%d �� !���ก ���"�#$%�&'$()� �&�'%*+ (int, short, unsigned short, long, unsigned
long
%u �� !���ก ���"�#$%�&'$()� �&�'%*+�&ก (unsigned short, unsigned long
%o �� !���ก ���"�#$22ก+ 3�������(2�'$(4 ���"%o �� !���ก ���"�#$22ก+ 3�������(2�'$(4 ���"
%x �� !���ก ���"�#$22ก+ 3�������(2�'$(4 ��6�!ก
%f �� !���ก ���"�#$%�&'$(78�69+ (float, double, long double)
%e �� !���ก ���"�#$%�&'$(78�69+22ก+ 3�������(2� E (!�<2 e) 9กก� $�� (float,
double, long double)
%c �� !���ก ���"�#$2�ก(�= 1 %�& (char)
%s �� !���ก ���"�#$(?2@& + (2�ก(�=+ กก&A 1 %�&)
%p �� !���ก ���"�#$%�&�BC%� �!�A� (pointer)
%�&29A �%�&29A �
main(){
int i =12345;float x=350.875;int i =12345;float x=350.875;
printf(5%d\n7,i);printf(5%f\n7,x);
}
#$$�DE�#$$�DE�
12345350.875000
���ก���� ���ก���� scanfscanf();();
� Scanf( ) H�ก3�?'D<I2���(?2+�$) ก��J�D6+D�• '�K����ก�������(?2+�$+ %�4 �3�L M C
� ��ก%,�ก&�1)&�&�2 � scanf( ) • +4 ���(?2+�$) ก keyboard �$?&�� Q�'ก*�Q&?3�• +4 ���(?2+�$) ก keyboard �$?&�� Q�'ก*�Q&?3�
%� �!�A�!�A&9@& +)� (memory address 7BI�=�R) "����5�ก&�����ก6�7 function scanf( ) ��&�7 �:;�%� �!�A�7BI29�A (address) (2�%�&���6�<�;/�+/&�=)&0>6<7function scanf( )
������ก �3�?� ����ก���� ������ก �3�?� ����ก���� scanfscanf();();
scanf(5format string7, &variable);
1. format string "O� ��3����#P���กQ�R<��กSTก����� ���� ����2. &variable (��$ก��UQ��R<2�R<26$"6���Q��#PVกW� ����) "O� �OX<�#PR<26$"6���Q��#P���VกW� ���� V�2<&name
%�&29A �ก �3�?� ����ก���� %�&29A �ก �3�?� ����ก���� scanfscanf();();
V�2< ��� ����V�O�<�3YV3Z<�Q�<6<VUW����"Q���P�
int month ,year;int month ,year;scanf(5%d %d7, &month, &year);
R�O�R�ก�#ก����� �����#V3Z<�\<=$���6$int i;
float x;
scanf(5%d %f7,&i,&x);
%�&29A �%�&29A �#include<stdio.h>
#include<conio.h>
int main()
{
int year;
float salary;
clrscr();
printf(“Insert year experience and salary : ”);
scanf(“%d %f”,&year,&salary);
printf(“You worked for %d years.\n”,year);
printf(“Your salary is %.2f\n”,salary);
return(0);
}