งาน#12. 1. ก
ก ก"#$ก
ก % & % '( ( & ) * + , -) ก% '
1.1 ก ก ก ก !"
1. ก - ก ( ก+ % % )' ( _ ) (0 1 ก+
() % % )' ก21
2. + , ( $ %5' ( % ' ก6 ( $ )2ก &' A
( % 1 '% a
3. % ก 8+ &' $ @ -) % &' (' %(' ก
4. ( & % ) ก6
5. 1 , ก6 (
' +,
3. 1.2 ! $
+, & ) * 3 ก);' %)ก ก () ( 2 () 8
< = -ก ( ) ก && ) %% &% '( ( '
! $ % ก ก
char -128 0> 127 ก
unsigned char 0 0> 255 ก 1 ' %
int -32768 0> 32767 ) ( 2
unsigned int 0 0> 65535 ) ( 2 1 ' %
short -128 0> 127 ) ( 2 -66
unsigned short 0 0> 255 ) ( 2 -66 1 ' %
long -2147483648 0> 2147483649 ) ( 2 -66 (
unsigned long 0 0> 4294967296 ) ( 2 -66 ( 1 ' %
float 3.4 x 10-38 0> 3.4 x 1038 ) 8 ( ) %) ; 6 %)ก
double 3.4 x 10-308 0> 3.4 x 10308 ) 8 ( ) %) ; 12 %)ก
long double 3.4 x 10-4032 0> 3.4 x 104032 ) 8 ( ) %) ; 24 %)ก
4. 1.3 ก ' ()
1.3.1 -66 1 1 ' ก % & )
&' printf (“2 x2 = %dn”,4)
1.3.2 -66 2 6 " '( %( = +,
-66 #define macro_name data;
1.3 ก
6 macro_name 1 & ก )
1.3.1
& ( $ %5'
data (“2 x2 = %dn”,4) )
printf
( ' #define PI 3.14; &' ()* +,- .- / 01) ,)
1.3.2 2 2 3 4&
#define macro_name data;
macro_name 1 / .-=* =>/ ?
1.3.3 ' () 13
data 6 ("FG ก$& %)ก
*' !"
const#define PI 3.14; = data;
variable
+$ variable & (-
data )
% const x = a*b
5. 2. ก ) ,
$ !$ % ก-
ก $& ก (
2.1 % $ ก ( $%. %
% $ ก .,( /, -
+ addition 6(ก
- subtraction )6
* multiplication "
/ division %
% remainder % 8+
6. 2.1 % $ ก , +
ก % a=3;b=2;
% $ ก .,( /, -
< less than ก('
> greater than กก('
<= less than or equal ก(' % ' ก6
>= greater than or กก(' % ' ก6
equal
== equal ' ก6
!= not equal 1 ' ' ก6
7. 2.3 % $ ก !$ % ก-
% $ ก .,( /, -
&& AND -)
|| OR %
! NOT
% 4* $ , % ก-
$
* -5 (X) * -5 (Y) !(X) (X)&&(Y) (X)||(Y)
F F T F F
F T T F T
T F F F T
T T F T T
8. 3. 4 ' ( " ก ก8 - if
)
(6 ; -66 if 3 )ก+" -66 if -66 if – else -) -66 if –
else if – else
3.1 ก )9!* -5 ' if
if ก %ก = 1 %1 '
ก 1 -)(1 -% ' &; ' 1 % ก 1 2 ก21 ' 1 %1
-% ' &; ' 1
9. 3.1.1 *' ก ) ' if
*' 1 ก "%) 1 if 1
if ( 1 )
' ; (ก " 1 )
&; ' 1 ; (ก " 1 2)
*' 2 ก "%) 1 if กก(' 1
if ( 1 )
{
ก);' ; (ก " 1 )
};
&; ' 1 ; (ก " 1 2)
10. 3.2 ก )9!* -5 ' if – else
if – else ก %ก 1 % &;
1 -)(1 &; ' 1 - '% ก 1 2 % &; 2 -)(1
&; ' 1
3.2.1 *' ก ) ' if – else
*' ก & -66 if – else
If ( 1)
&; 1 (ก " 1 );
else
&; 2 (ก " 1 2 );
&; ' 1 ;
# % ก- ') )ก กก(' 1 & % {}ก 6
11. 3.3 ก )9!* -5 ' if – else if – else
if – else if – else ก %ก 1 1 %
&; 1 -)( &; ' 1 % ก 1 1 2 % ( 6('
1 2 % 1 '% ก 1 2 % &; 2 -)(
&; ' 1 % ก 1 2 2 % ( 6(' 1 n % 1 '% ก 1
n % &; n -)( &; ' 1 % ก 1 n 2
% '%) else -)( &; 0 1
12. 3.3.1 *' ก ) ' if – else if – else
*' -66ก -66 if – else if – else
if ( 1 1)
&; 1 ; (ก " 1 1 )
else if ( 1 2)
&; 2 ; (ก " 1 2 )
…..
else
&; n ; ( ก % ก 1 )
&; ' 1 ;
% ก- ') ) ก กก(' 1 & % {}ก 6
13. 4. 4 ' )( " ก ก8 - switch
ก (6 ; ก & ก +, ก ก if -)(
switch % ) ก 1 & (6 ; ก -66 ) ก ก " ) กก
( ก ( ' &' <)ก -66 8 6% ก & if -66
ก = ( 6 ( ก %' 1 ก +,
ก-66 switch % )ก+" ( %$ ( 6 ' (- % $('
ก6 case ก (6 ; case
- '% ก ( 6-)(1 ' ก6 ) default (<;
1 ') ก default ก21 )
14. 4.1 *' ก ) ' -' ( ; ' switch
Switch { var / expression}
{
case ' 1 : &; 1;
break ;
case ' 2 : &; 2;
break ;
case ' n : &; n;
break ;
: ;
}
1 ,. P Q
15. ก< - () 1
*= (% ก !$ ! ก4 () 2
! $ <'ก
4 () 4
$(+$ก + $ .8 () 5
?@ - () 6
+ ( 4 () 8
* $ ( C;(/ ( () 9
$(+$ @ ($, () 12
!E .6/1