ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
& ???????? ? ? ??????????? ???? C PROGRAMMING '
&'
?.?. ???????
C PROGRAMMING ???? Program Language ???????????????????????????????????????????????
????????????? ???????????????????????????? ?
?.?. ?????????????????? Dev C++
?????????????????????????????????????? Dev C++ ??????????????????????????????
?. ??? Start Menu
?. All Program
?. Blooddshed Dev C++
?. ??? Tick ?????????? Don?t Deplay tips as Startup
?. ??? Close
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.?. ??????????? Source File
???????????? Source File ???????????????????? ?
?. ??? File Man u
?. New
?. Source File
?.?. ???????? Source File
?????????? Source File ???????????????????? ?
?. ??? File Man u
?. Save ? Save As
?.??? File Name ??????????? ?? (nak.cpp)
?.??????????????????????????? File
?. ??? Button Save
?.?. ???????? Cord ???????
Source Code: Output
#include<stdio.h>
#include<conio.h>
main(){
printf ("Hello chhynak.n") ;
printf ("How Are You.n") ;
getch();
return (0);
}
Hello chhaynak
How are you
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.?. ????????????? Source Code
- #include<stdio.h> : ?????? Standard Input/output ??????????????? Function ???
?? Printf ????????????? Prinf ?????????????? #include<stdio.h> ???? ???????????
Header file ???????? ?
- #include<conio.h> : ?????? Function??????????? Getch();??????? Prinf ?????????
????? #include<stdio.h>
- main(){} : ?????? Main Fucntion ?????????? ? ???? Code ?????? Program ?????? ?
- Printf : ?????????? ??????????????????? Command CMD
- Getch(): ?????????????? ? ???? Code ?????? Press Anykey ??????????? ? ????????
?.?. ??????????? CORD
Ex.
?.?. ????????? Character
Escape character ? Escape code ??????????????????????????? source code ? ???????? ????????? ??
??????? ?????? ?
Code ???????? Code
t tab ???????? ??
a alert (beep)
n Newline ????????? ??
' single quote (')
? question mark (?)
#include<stdio.h>
#include<conio.h>
main(){
Statement;
..........
getch();
return (0);
}
#include<stdio.h>
#include<conio.h>
main(){
printf ("Hello chhynak.n") ;
printf ("How Are You.n") ;
getch();
return (0);
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.
Output
?.?. ???????????? COMMENT
?????????????????? Command ?????????????????????? ??????? Programer ???????? Command
???????????????????? Code ??? ?? ?? ????????????????????????
?.?. ?????????????
???????????????????????????????????? ??????????????????????? ?
?. ??? ??????????
?.???
?.????? ??
?.?????????????? ?
?.???????? ?
?.???????
?.??????????
&??????????? ?'
#include <stdio.h>
#include<conio.h>
main(){
printf("Hello ! this is:t "chhaynak"n");
printf("What's are you doing?n");
printf("Working");
getch();
return (0);
}
Hello ! this is chhaynak
what¡¯s are you doing?
Working
/* this command for tell
you what is this > */
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
& ???????? ? ? ???? ??????????????? '
&'
?.? ????????????
?????????????????????????? ????????????????????????? ? ?????????????????????????
???????????????????????? ?
Syntax : Data type Variable
Ex. int a;
?????????????????????????? ?
Name Description Size Range
Short Short integer 2byte Signed:-32768 to 32767
Int integer 4byte Signed:2147483648 to 214748347
Long Long integer 4byte Signed:2147483648 to 214748347
Float Float point number 4 byte -3.4 x 10-38
TO 3.4 x 10-38
Double Double precision floating point number 8 byte +/-1.7e+/-308(~15digits)
Boolean Boolean value 1 byte True or False
Char Character or small integer 1byte Signed:-128 to 127
Code ?????????????????? Test ??????????? Data type
#include<stdio.h>
#include<conio.h>
main( ) {
printf( ¡°Fundamental of size of operator.nn¡± );
printf( ¡°Size of char %3d byte.n¡±, sizeof( char ) );
printf( ¡°Size of int %3d byte.n¡±, sizeof( int ) );
printf( ¡°Size of long %3d byte.n¡±, sizeof( long ) );
printf( ¡°Size of short %3d byte.n¡±, sizeof( short ) );
printf( ¡°Size of signed %3d byte.n¡±, sizeof( signed ) );
printf( ¡°Size of unsigned %3d byte.n¡±, sizeof( unsigned ) );
printf( ¡°Size of float %3d byte.n¡±, sizeof( float ) );
printf( ¡°Size of double %3d byte.n¡±, sizeof( double ) );
printf( ¡°Size of long double %3d byte.n¡±, sizeof( long double ) );
printf( ¡°nPress < Enter to Exit ! >¡± );
getch( );
return ( 0 );
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.?. ??? ??????
??????????? ?????????????????????????????????? ( Data )???????????? ?????????????? ? ?????
??????????????????????????????? ?
-??????????? A ?? Z ( ??? ?? ?? ) ??? ??? Underscore
-???????? ??????????????? ? Underscore
-???????? ? ?? ??????? Variable Name ?? ????????? ??????? ????????????
-??????????????????? Keyword ? Keyword ???????? ?
Array for return break function sizeof
case goto if constants switch continue
labels pointer union
??????????????????? ?????????????????????????? ?
-total$ : (Illegal character $) ??????????????? $
-2nd_sums : (Begin with a digit) ????????????????????????
-second sum : (Cannot use blank as a character) ?????????????
-Total-Cars : (Illegal character -) ??????????????????? ¡°-¡±
????????????? Output ???????????????? ??????? Printf(); Fucntion ???????? Formation Control Data Type
??????????? ???????????????????? ?
Quantity Data Type
%d, %i Integer (int) ????????
%c Single character (char) ????????????
%s Character string (char) ??????????????
%f Fractional number (float) ???????????
%lf Double fractional number (double) ???????????
%ld Long Integer (long) ????????
?.?.????????????
????????????????????? ????????????? ?????????????????????????????????? ? ????????????
??? ???????????????????????? ??????????????????????? ? ??????????????????????????? ?
Ex. int a,b,sum;
float c;
??????????????? ??????????????????????????? ?????????????? ???????????? ?
Ex char c = ?A?;
int i = 0;
int k = i + 1;
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.?.????????????????
1. Arithmetic Operator: ???? Operator ???????? ??????????????????????????????????????????
?????? Program .? Arithmetic Operator ????
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus [remainder of an integer division.]
Arithmetic Operator ???????? ? ???? ??? ??? ???? ?????????????????????????????????? ????
????????????? Modulus ???????????????????????????????????? ?
??????? int a=1;
int b=6;
int c= a+b;
2 ¨C Relational and Equality Operator: ??????????????????????????????????????????????????
????????????????? ???????????????????? ??????? Loop Statement , if-else Staement ,.....?
Relational and Equality Operator ???????? ?
< ?????? ( Less than ) <= ???????????? ( Less than or Equal )
>????? ( Greater than ) >= ??????????? ( Greater than or Equal )
== ????? !=????????
3 ¨C Logical Operator: ????????? ?????????????????? ?????? ?????????
Logical Operator ???????? ?
&& ?? ?????
|| ?? ???
4. Increment and Decrement Operator : ???????? C ?????????????????????????????????????
???????????????????? ( Increment ) ??? ???? ( Decrementing ) ????????????? ? ????????? Increment
(++) ??????????????? ??????????????????? ? ????????? Decrement (--) ???????????????
??????????????????? ?
???????????????????????????????????????????????? ?? ? ?????????????? Constant ?????????
? ??????????????????????????? ?????????????????????? (++n)????? ????????????????? ( n++)?
????? ???? -(++n) ??????????????????????????? ( Ex. n=5 , x=++n , ???????? x=6 )
-(n++)???????????????????????????? ( Ex. x=n++, x=5, n=6)
]TahrN_2?
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
#include<stdio.h>
main ( ) {
int a = 5;
int b = 5;
printf( ¡°Value of a: %d and b: %dn¡±, a, b );
printf( ¡°Value of a: %dn¡±, ++a );
printf( ¡°Value of b: %dn¡±, b++ );
getch();
return ( 0 );
}
RbmaNviFI Prefix nig Postfix nwgdUcK?aenAeBlEdleyIgeRbIvaEt?g
5. Assignment operator: eKmanRbmaNvIFImYycMnYneTotenAelIRbmaNviFIFm?ta EdleKeRbIsMrab; Assigned
(=) [ep?rtM¨¦l]b¡èKNnakenSamepSg?.RbmaNviFIenHKW ?
Operator Simple Equal Meaning
+= a+=b a = a + b a ???????? b ? ?? a ????????????
-= a-=b a = a ¨C b a ??????? b ? ?? a ????????????
*= a*=b a = a * b a ?? ????? b? ??a ????????????
/= a/=b a = a / b a ???????? b ? ?? a ????????????
%= a=b%b a = a % b
a ??????? b ? ?? a
???????? ?????????????? a
??? b
]TahrN_3 ?
#include<stdio.h>
main ( ) {
int a = 1;
int b = 5;
printf( ¡°Value of a: %d and b: %dn¡±, a, b );
a += b;
printf( ¡°Value of a: %dn¡±, a );
b %= 3;
printf( ¡°Value of b: %dn¡±, b );
b *= a + 1;
printf( ¡°Value of b: %dn¡±, b );
b /= a - 1;
printf( ¡°Value of b: %dn¡±, b );
getch();
return ( 0 );
}
?????? ? ???????? ??? Output ??? Program ???????? ?
1. ?????????????????????????? ?
-???????????????????? ( S=a*b)
-?????????? S=a+b+d+d
-?????????????????? S=a*a
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
& ???????? ? ? Control Structure '
&'
?.?.If Statement
?????? Expression ??? (Expression ??????????????????? ) Statement ?????????????? ???????????
????? ??? Expression ?????? ( Expression ???????????????? ) ????????????? Statement 2 ? ????????????
C Programing Statement ????????????? ??????????? Semicolon ¡° ; ¡± ?????????? Block Statement ?????
????????????? Braces ¡°{???}¡± ????????????????? ? ??????? if Statement ??? Syntax ??????????? ?
Syntax1:
Syntax2:
??????? ? ?
#include<stdio.h>
main( ) {
int x;
clrscr( );
printf( ¡°Input x:¡± );
scanf( ¡°%d¡±, &x );
if ( x == 10 ) {
printf( ¡°n This is a good student.¡± );
}
return ( 0 );
}
??????? ? ?
#include<stdio.h>
#include<stdlib>
main( ) {
int magic, guess;
printf( ¡°nPlease input Guess value: ¡° );
scanf( ¡°%d¡±, &guess );
magic = rand( );
if ( guess == magic )
printf( ¡°n You are right.¡± );
if ( guess < magic )
printf( ¡°n You are too low.¡± );
if ( guess > magic )
printf( ¡°n You are too high.¡± );
printf( ¡°n %d is the magic value¡±, magic );
getch( );
return 0;
}
if(expression )Statement;
Statement2;
if(expression ){
Statement1;
Statement2;
..........
..........
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.?.If ¨Celse Statement
???????? Expression ??? Statement 1 ?????????????? ????? Statement ????????? Statement2
??????????? ?
?????? :
???????? ? ?
???????? ? ?
if(expression ){
Statement1;
}
else}
Statement2;
}
???????????
#include<stdio.h>
#include<conio.h>
main( ) {
if (result >= 45){
printf("Passn");
}
else{
printf("Failn");
getch();
}
}
???????????????? ?
#include<conio.h>
#include<math.h>
void main(){
clrscr();
int a,b,c;
float Deta,x1,x2;
printf("Input A=");
scanf("%d",&a);
printf("Input B=");
scanf("%d",&b);
printf("Input C=");
scanf("%d",&c);
Deta=(pow(b,2)-(4*a*c));
if(Deta==0){
x1=x2=(-b/(2*a));
printf("x1=x2=%0.2fn",x1);
}
else if(Deta<0)
printf("No rootn");
else{
x1=(-b-sqrt(Deta))/(2*a);
x2=(-b+sqrt(Deta))/(2*a);
printf("X1 is=%0.1fn",x1);
printf("X2 is=%0.1fn",x2);
}
getch();
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
???????? ? ? ??????????????????????????????????????????????????????
1¡­Book [ -????????????????? ?? ???? ????????????
-?????????????????? ?? ??? ?? ???? ????????? ? %
-?????????????????? ?? ??? ?? ???? ????????? ?? % ]
2¡­Pen [ -?????????????? ?? ???? ????????????
-??????????????? ?? ??? ?? ???? ????????? ? %
-??????????????? ?? ??? ?? ???? ????????? ?? % ]
2¡­Ruler [ -?????????? ??????? ?? ???? ????????????
-?????????? ???????? ?? ??? ?? ???? ????????? ? %
-?????????? ???????? ?? ??? ?? ???? ????????? ?? % ]
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main(){
Again:
clrscr();
int book,pen,ruler,U_price;
float t_book,t_pen,t_ruler,t_all;
char ch;
gotoxy(33,2);
textbackground(GREEN);
textcolor(RED);
cprintf(" THINKING MONEY ");
//BOOK
gotoxy(27,4);
printf("Input Qauntity Book: ");
scanf("%d",&book);
gotoxy(27,5);
printf("Input unit price : ");
scanf("%d",&U_price);
if(book<=15){
t_book=book*U_price;
gotoxy(25,6);
textcolor(YELLOW);
cprintf("You have to pay = %0.1f Rilen",t_book);
}
if(book>15 && book<=30){
t_book=(book*95/100)*U_price;
gotoxy(25,6);
textcolor(YELLOW);
cprintf("You have to pay = %0.1f Rilen",t_book);
}
if(book>30 && book<=60){
t_book=(book*90/100)*U_price;
gotoxy(25,6);
textcolor(YELLOW);
cprintf("You have to pay = %0.1f Rilen",t_book);
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
//PEN
gotoxy(27,8);
printf("Input Qauntity Pen : ");
scanf("%d",&pen);
gotoxy(27,9);
printf("Input unit price : ");
scanf("%d",&U_price);
if(pen<=15){
t_pen=pen*U_price;
gotoxy(25,10);
textcolor(YELLOW);
cprintf("You have to pay =%0.1f Rilen",t_pen);
}
if(pen>15 && pen<=30){
t_pen=(pen*95/100)*U_price;
textcolor(YELLOW);
gotoxy(25,10);
cprintf("You have to pay = %0.1f Rilen",t_pen);
}
if(pen>30 && pen<=60){
t_pen=(pen*90/100)*U_price;
textcolor(YELLOW);
gotoxy(25,10);
cprintf("You have to pay = %0.1f Rilen",t_pen);
}
//Ruler
gotoxy(27,16);
printf("Input Qauntity Ruler : ");
scanf("%d",&ruler);
gotoxy(27,17);
printf("Input unit price : ");
scanf("%d",&U_price);
if(ruler<=15){
t_ruler=ruler*U_price;
textcolor(YELLOW);
gotoxy(25,18);
cprintf("You have to pay = %0.1f Rilen",t_ruler);
}
if(ruler>15 && pencil<=30){
t_ruler=(ruler*95/100)*U_price;
textcolor(YELLOW);
gotoxy(25,18);
cprintf("You have to pay = %0.1f Rilen",t_ruler);
}
if(ruler>30 && ruler<=60){
t_ruler=(ruler*90/100)*U_price;
textcolor(YELLOW);
gotoxy(25,18);
cprintf("You have to pay = %0.1f Rilen",t_ruler);
}
t_all=t_book+t_pen+t_ruler;
textcolor(YELLOW);
gotoxy(25,20);
cprintf("TOTAL All TO PAY = %0.1f Rile",t_all);
gotoxy(31,24);
textcolor(YELLOW+GREEN);
cprintf("Continue Program (Y/N)?");
fflush(stdin);
ch=getchar();
if(ch=='Y' || ch=='y')
goto Again;
if(ch=='N' || ch=='n')
exit(1);
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.?.If ¨Celse ¨Cif Statement
if ¨C else_if Statement : ????????????????? if-else statement ???????????????????????????????????
???? ????? ( ?????? ? ) ???????????????? if-else-if Statement ??????????? ?
?????? :
??????? ? ? ????? ? Message ??????? ? ??? ??????????????? ? ???
if ( expression 1)
statement 1;
else if ( expression 2)
statement 2;
else if ( expression 3)
statement 3;
else if ( expression n-1)
statement n-1;
else
statement n;
}
#include <iostream>
#include<conio.h>
int main(){
int age;
scanf("%d",&age);
if ( age < 100 ) {
printf("You are pretty young!n");
}
else if ( age == 100 ) {
printf("You are oldn");
}
else {
printf("You are really oldn");
}
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
??????? ? ? ?????????????????????
??????? ? ? ?????????????????? ??????
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.? .Switch Statement
Switch Statement ????????????????????? if-else-if ??? ?????????? if-else-if Statement
??????????????????? Variable ???????? ???????? ? ???? ?????????? Switch Statement ?????????? ?
??????
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
Ex 1.
Ex 2.
#include<stdio.h>
#include<conio.h>
void main(){
clrscr();
int n;
printf("Input N=");
scanf("%d",&n);
switch(n){
case 1:
printf("Number one");
break;
case 2:
printf("Number two");
break;
case 3:
printf("Number three");
break;
case 4:
printf("Number four");
break;
default:
printf("The Number biggest is=%d");
}
getch();
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.? .??????
?. ???????? Outpute Code ???????? ?
int x,y;
x=6;
y=1;
if(x<2)
printf(¡°%dn¡±,x);
else
printf(¡°%dn¡±,y);
?. ???????????????????????
-??????????????????????? Ax+b=0
-?????????????????????????? C ?????????????????????????????????????? ????????? ?????? ?
-????????????????????? Switch ?????????????????????????
&??????????? ?'
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
& ???????? ? ? Loop Control Structure '
&'
???????????????? ???????????? ???????? ???? Repeat Statement ? ??? Block Statement ????????
???????????? ???? Loop ? ?????????? C Loop ????? ????? ?? ?
?. While Loop Statement
?. do_while Loop Statement
?. For Loop Statement
Loop ???????????? Instruction Computer ?????? ???????????????????? ???????????????
?????????????????? Control Variable ??????? ?
?.? .While Loop Statement
??????? While Loop ???????????????? Expression ??????????? ????? Statement ???? While Loop
???????????????( Execute ) ???????????????????? Expression ??????? ????????????????? ????? Statement
? Block Statement ?????????? Execute ???? ??????? Expression ?????? ?
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
??????? ?
?.? .Do-While- Loop Statement
??????? do While Loop ?? Execute ??? Statement ????????????? Loop ?????????????????????
???? Expression ? ????????????????????? Expression ??????? ????? Statement ?????? Execute ???
????????????? ?? ????????????????????? Expression ?????? ?
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
??????? ? ?
??????? ? ?
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
??????? ? ?
?.? .For Loop Statement
???? For loop ??????????? ? ???????? ??????????????????????????????????? ???????? ?
?????????? ??????? ??????? Loop ????????????????? ? ?? ???????????? ? ????????????????????????????????? ?
???????? For Loop :
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
??????? ? ?
????? ?
??????? ? ?
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
??????? ? ?
????? ?
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
??????? ? ? ?????????????? ??? ??????
??????? ? ? ???????????????????? ?
?.? .Goto Statement
???????????????? ????? ? ??????????????? ????? Statement ??????????????? ?
??????????? Goto label
identifier ??????? ?????????????????? Goto statement ?? Execute ??? Statement ????????? ??????? ?
????????????????
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
&??????????? ?'
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
& ???????? ? ? Function '
?.? .???????????
????????????????????? ??? ??????????? ? ??????????????????? ????????????? ??????????????
?????????????????????????? ??????????? ? ??????????????????????? ????????????????????? ?????
????????????????????? ?????????????????? ??????????????????????????? ?????????????????? ????????????
??????????????? Error ????????????????????? .? Function ???????? ?
- sub prigram
- ???????????????????????????????????
- ???????????????????????? Error ?????????
- ???????????? Memory
- ????????????????????? ?????????????????
?.? .????????? ???? Sub Program or Function
???????????? C ? C++ Function ????????????????? ??? ?? ?
-Standard Library Function
-Function ?????????????? Programmer
1¡­ Standard Library Function
????????????????????????????????????? ????? ???????? Computer ??????????? ? ?????
Function ??????????????? ?????????? Header file ? Standard Library Fucntion ?????????????????? ?
????????????????? ? Printf , scanf , goto;
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.? .Function Declaration
???????????? Function ???????????? Function ???????????? ? ??????????????????? ? ??
????? Main() Fucntion ? ?????????????????????? Compiler ?? Code ???? Function Decleration ????????
????? ? Function Declatation ?????????? ?????????? Semicolon (;)
?.? .??????? Call ???????
??????????????? Call ??????? ??????????????????????????????????????? ?
-? ?????????????????????? Main(): ????????????????????????? Local ?????? ?? ????????
??????????? Function ???????????????? Main() ???????????????????????? ?
-? ?????????????????????? Main(): ????????????????????????? External Function ??
???? Function ??????????????????????????????????????????????????????? ?
?.? .Return Statement
?????? C program ???????????????????? Return Statement ?????? C program ??????????????
Function ?????????????? ? mian() Function ?????? ? return statement ????????????????????? ????? Execute
??????? Function ??????? ? ??????????? Function ??????????????? Reurn ?? ?
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.? .??????
&??????????? ?'
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
& ???????? ? ? Array '
?.? ???????
Array ????????????? Variable ?????? Data type ????? ????????? ???????? ??????????????? Array
?? Variable 1 ??????????????????????????????? ???????????? ??????????????? ?
-???????????????? Array ???? Index ???? Subscripts ????????????? ? ??? Index=0 ?????? ????
????? n ?????? Index = n-1
-???????? Array ???????????????? ?????????????
-Data type ????????????????
-Array_Name ??????? ?????? Array
-Length ????????? ? ???????? Array
Ex ? .
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?????
Ex ? .
?????
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.? Two Dimensional Array
???????? C ??????????????????????????? Array ??????? ( Two dimension arrays ) ????????????????
?????????????? Array ???????? ?
??????? ? ????????? Array ??????????????????? ?
float dr [4] [5];
????? ???????? ?? Variable ??????? float ???????????????? ????????????????? ?
???????
dr[0][0] dr[0][1] dr[0][2] dr[0][3] dr[0][4]
dr[1][0] dr[1][1] dr[1][2] dr[1][3] dr[1][4]
dr[2][0] dr[2][1] dr[2][2] dr[2][3] dr[2][4]
dr[3][0] dr[3][1] dr[3][2] dr[3][3] dr[3][4]
?.? Array and Function
????????????? Array ?????????? Int ?????? 10 ?????( Element) ?? Int(10)? ????????????????
????? ?????? ? ???????? ?????????? Array ?????????????????? ? ?????????????????????????????????
?? ? ?????????????????? Parameter ?????? ? ???? Parameter ??????? Array
????????????????????????? ?
????????????????????? Function ??? Argument ???????? Array ???????? ?? ??????????? ?
1. void Array_Function ( int b[10]);
2. void Array_Function ( int b [ ], int n )
????????? ( Call ) Function ??????????? ????????????????
1. Array_Function(b)
2. Array_Function(b,n)
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.? Array String
??????? C ?? ??????????????? String ?????????????????????? ? ???????????? C String ???????????
????????? Array ??? Character ? ????????????? String ?????????????????????? ????????????
Memory Location ??????????? String ???? Array ??? Array ?????? Dimension ?????????????? ?
Location ???? Memory ? ?????????? String ????????????????? ?????? Null (??n?) Charater ?
??????? Char str[10]=¡±Computer¡±
??????? ?
?.? ??????
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?????????????????? ???????????????????????
&??????????? ?'
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
& ???????? ? ? Pointer '
?.? ???????
Pointer ??????????????????? ??????????????????????????????? ????????????? Address
???????????? ?????????????????????????? Pointer ??????????????????? Address ???????? ????????????
??????????????? ????????? ???????????????????????????????? ?
?.? ?????????? Pointer
??????????????? Pointer ????????????????? ????? ?????????? ( * ) ?????????????? ?
??.
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.? Pointer to Pointer
??????????? Pointer ?????????????????????? ???? ?????????????????????????? ?? Pointer
???????????? ????? Pointer ?????????????????????????????? ?
??????? ?
?.? Pointer to Function
??????? Pointer ????????????? Address ??????????????? ???????????? Adress ???????????? ?
??????????????????? ????????????
??????? ? ?
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x = 10;
int *a;
int **b;
int ***c;
a = &x;
b = &a;
c = &b;
printf("value of x = %dn",x);
printf("value of x by using a = %dn",*a);
printf("value of x by using b = %dn",**b);
printf("value of x by using c = %dn",***c);
getch();
}
#include<stdio.h>
#include<conio.h>
void change(int,int*);
void main()
{
clrscr();
int a = 10 , b = 20;
printf("Before calling function.n");
printf("a = %d n",a);
printf("b = %d n",b);
change(a,&b);
printf("After calling function.n");
printf("a = %d n",a);
printf("b = %d n",b);
getch();
}
void change(int x,int *y)
{ x = x * 5;
*y = *y + x;
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
??????? ? ?
&??????????? ?'
#include<stdio.h>
#include<conio.h>
int (*psum)(int,int);
int sum(int,int);
void main()
{
clrscr();
int a = 40 , b = 20 ;
psum=&sum;
printf("Result = %d",(*psum)(a,b));
getch();
}
int sum(int m , int n)
{
int s;
s = m + n ;
return (s);
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
& ???????? ? ? File '
?.? ???????
????????? ? ????? ????????????????????????????????????? ??????? ??????????? ????? Hard
Disk , Flash ?????? ? ????????????? C Program File ???? Byte ????????? ????????? ???? ?????? ??????????
???????????????????? ?? Text File ??? Binary File ?
?.? ?????????? File
?.? ?????????? Text File
???? File ????????????????????????? Graphic Character ????????????????????? FIle ???????????
???????????????????????????????? ? ???????? ???????? ? ????????????? File ????????????
File Pointer ????????????????????????? File ???????????? ???????????? ?????????? ? ??????????????
??????? fopen() ?
??????
-FileName : ??????? ?????? File ?????? FileName ??? Execute ???????????????????
-Model : ???? String ?????????????????????????????????????????????????????????
Mod ??????
r/rt ??? Text File ???????????????? , ????? ? FIle ????? error
w/wt ??? Text File ?????????????????? , ????? ? FIle ??????????????
a/at ??? Text File ??????????????????,????? ? FIle??????????????
r+/r+t
??? Text File ??????????? ???????? ? ??????????w+/w+t
a+/a+t
fp=fopen(¡°FileName¡±,¡±Model¡±)
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.?.? ???? File ??????????
?????????????????????????????????????????????????????? file ??? ? ??????? putc(), fputc();
??????????????????????? ????????????????????????? File ????? File Pointer ?
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char ch;
FILE *fp;
fp=fopen("Test1.txt","w");
if(fp==NULL)
printf("Opening file was Error");
else
{ printf("Input character store infile.n");
printf("Press <Esc to stop>n");
do
{
ch=getch();
if(ch!=27)
{
putchar(ch);
fputc(ch,fp);
}
}
while(ch!=27);
}
fclose(fp);
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.?.? ???? File ?????????
???????????????????????????????????????????????????? file ??? ? ??????? getc(), fgetc();
????????????????????????????????????????????? File ????? File Pointer ?
#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
char ch;
FILE *fp;
fp=fopen("Test1.txt","r");
if(fp==NULL)
printf("Opening file was Error.");
else
{ printf("Read data from Filen");
ch=getc(fp);
while(ch!=EOF)
{ putchar(ch);
ch=getc(fp);
}
}
fclose(fp);
getch();
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.?.? ???? Text File ??????????????????
?????????????????????????????????????????????????????? file ??? ? ??????? putc(), fputc();
??????????????????????????????????????????????? File ????? File Pointer ?
#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
char ch;
FILE *fp;
fp=fopen("Test1.txt","a");
if(fp==NULL)
printf("Opening file was Error");
else
{ printf("Input character to append in
file.n");
printf("Press <Esc to stop>n");
do
{ ch=getch();
if(ch!=27)
{ putchar(ch);
fputc(ch,fp);
}
}while(ch!=27);
}
fclose(fp);
}
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
?.? Binary File
Binary File ??????????????????????? Internal Format ????????????????????? File ?????????????
????????????????? int , long , double , float ?????? ? ??????????? ???????? ? ????????????? File
????????? ??? Text File ??? ???????????????? mode ?????? ?
&??????????? ?'
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????
www.kompongsom4u.blogspot.com IT Book C Programming
?????????? 070 908 739
?????????????????

More Related Content

What's hot (20)

PPT
Problem solving using Computer
David Livingston J
?
PDF
Sorting and Searching Techniques
Prof Ansari
?
PDF
Handwritten Text Recognition and Digital Text Conversion
ijtsrd
?
PDF
Autoencoder
HARISH R
?
PDF
How to Work with Dev-C++
Deepak Jha
?
PPTX
Our presentation on algorithm design
Nahid Hasan
?
PPTX
Emotion based music player
Nizam Muhammed
?
PDF
Artificial Neural Network
Atul Krishna
?
PPTX
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
Simplilearn
?
PDF
Deep learning seminar report
SKS
?
PPT
Intro to Deep learning - Autoencoders
Akash Goel
?
PPTX
Attention in Deep Learning
½¡³Ì Ñî
?
PDF
Machine learning Summer Training report
Subhadip Mondal
?
PPTX
Artificial Neural Network ANN
Abdullah al Mamun
?
PDF
Goal based agent
LamisaFaria
?
PDF
Air Pollution Prediction using Machine Learning
IRJET Journal
?
PPTX
UNIT-4.pptx
NiharikaThakur32
?
PPT
Human Computer Interaction Unit III Part 2
ashodhiyavipin
?
PDF
Web scraping in python
Viren Rajput
?
PPTX
Modern Programming Languages - An overview
Ayman Mahfouz
?
Problem solving using Computer
David Livingston J
?
Sorting and Searching Techniques
Prof Ansari
?
Handwritten Text Recognition and Digital Text Conversion
ijtsrd
?
Autoencoder
HARISH R
?
How to Work with Dev-C++
Deepak Jha
?
Our presentation on algorithm design
Nahid Hasan
?
Emotion based music player
Nizam Muhammed
?
Artificial Neural Network
Atul Krishna
?
What Is Deep Learning? | Introduction to Deep Learning | Deep Learning Tutori...
Simplilearn
?
Deep learning seminar report
SKS
?
Intro to Deep learning - Autoencoders
Akash Goel
?
Attention in Deep Learning
½¡³Ì Ñî
?
Machine learning Summer Training report
Subhadip Mondal
?
Artificial Neural Network ANN
Abdullah al Mamun
?
Goal based agent
LamisaFaria
?
Air Pollution Prediction using Machine Learning
IRJET Journal
?
UNIT-4.pptx
NiharikaThakur32
?
Human Computer Interaction Unit III Part 2
ashodhiyavipin
?
Web scraping in python
Viren Rajput
?
Modern Programming Languages - An overview
Ayman Mahfouz
?

C program

  • 1. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ?????????????????
  • 2. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? & ???????? ? ? ??????????? ???? C PROGRAMMING ' &' ?.?. ??????? C PROGRAMMING ???? Program Language ??????????????????????????????????????????????? ????????????? ???????????????????????????? ? ?.?. ?????????????????? Dev C++ ?????????????????????????????????????? Dev C++ ?????????????????????????????? ?. ??? Start Menu ?. All Program ?. Blooddshed Dev C++ ?. ??? Tick ?????????? Don?t Deplay tips as Startup ?. ??? Close
  • 3. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.?. ??????????? Source File ???????????? Source File ???????????????????? ? ?. ??? File Man u ?. New ?. Source File ?.?. ???????? Source File ?????????? Source File ???????????????????? ? ?. ??? File Man u ?. Save ? Save As ?.??? File Name ??????????? ?? (nak.cpp) ?.??????????????????????????? File ?. ??? Button Save ?.?. ???????? Cord ??????? Source Code: Output #include<stdio.h> #include<conio.h> main(){ printf ("Hello chhynak.n") ; printf ("How Are You.n") ; getch(); return (0); } Hello chhaynak How are you
  • 4. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.?. ????????????? Source Code - #include<stdio.h> : ?????? Standard Input/output ??????????????? Function ??? ?? Printf ????????????? Prinf ?????????????? #include<stdio.h> ???? ??????????? Header file ???????? ? - #include<conio.h> : ?????? Function??????????? Getch();??????? Prinf ????????? ????? #include<stdio.h> - main(){} : ?????? Main Fucntion ?????????? ? ???? Code ?????? Program ?????? ? - Printf : ?????????? ??????????????????? Command CMD - Getch(): ?????????????? ? ???? Code ?????? Press Anykey ??????????? ? ???????? ?.?. ??????????? CORD Ex. ?.?. ????????? Character Escape character ? Escape code ??????????????????????????? source code ? ???????? ????????? ?? ??????? ?????? ? Code ???????? Code t tab ???????? ?? a alert (beep) n Newline ????????? ?? ' single quote (') ? question mark (?) #include<stdio.h> #include<conio.h> main(){ Statement; .......... getch(); return (0); } #include<stdio.h> #include<conio.h> main(){ printf ("Hello chhynak.n") ; printf ("How Are You.n") ; getch(); return (0); }
  • 5. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?. Output ?.?. ???????????? COMMENT ?????????????????? Command ?????????????????????? ??????? Programer ???????? Command ???????????????????? Code ??? ?? ?? ???????????????????????? ?.?. ????????????? ???????????????????????????????????? ??????????????????????? ? ?. ??? ?????????? ?.??? ?.????? ?? ?.?????????????? ? ?.???????? ? ?.??????? ?.?????????? &??????????? ?' #include <stdio.h> #include<conio.h> main(){ printf("Hello ! this is:t "chhaynak"n"); printf("What's are you doing?n"); printf("Working"); getch(); return (0); } Hello ! this is chhaynak what¡¯s are you doing? Working /* this command for tell you what is this > */
  • 6. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? & ???????? ? ? ???? ??????????????? ' &' ?.? ???????????? ?????????????????????????? ????????????????????????? ? ????????????????????????? ???????????????????????? ? Syntax : Data type Variable Ex. int a; ?????????????????????????? ? Name Description Size Range Short Short integer 2byte Signed:-32768 to 32767 Int integer 4byte Signed:2147483648 to 214748347 Long Long integer 4byte Signed:2147483648 to 214748347 Float Float point number 4 byte -3.4 x 10-38 TO 3.4 x 10-38 Double Double precision floating point number 8 byte +/-1.7e+/-308(~15digits) Boolean Boolean value 1 byte True or False Char Character or small integer 1byte Signed:-128 to 127 Code ?????????????????? Test ??????????? Data type #include<stdio.h> #include<conio.h> main( ) { printf( ¡°Fundamental of size of operator.nn¡± ); printf( ¡°Size of char %3d byte.n¡±, sizeof( char ) ); printf( ¡°Size of int %3d byte.n¡±, sizeof( int ) ); printf( ¡°Size of long %3d byte.n¡±, sizeof( long ) ); printf( ¡°Size of short %3d byte.n¡±, sizeof( short ) ); printf( ¡°Size of signed %3d byte.n¡±, sizeof( signed ) ); printf( ¡°Size of unsigned %3d byte.n¡±, sizeof( unsigned ) ); printf( ¡°Size of float %3d byte.n¡±, sizeof( float ) ); printf( ¡°Size of double %3d byte.n¡±, sizeof( double ) ); printf( ¡°Size of long double %3d byte.n¡±, sizeof( long double ) ); printf( ¡°nPress < Enter to Exit ! >¡± ); getch( ); return ( 0 ); }
  • 7. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.?. ??? ?????? ??????????? ?????????????????????????????????? ( Data )???????????? ?????????????? ? ????? ??????????????????????????????? ? -??????????? A ?? Z ( ??? ?? ?? ) ??? ??? Underscore -???????? ??????????????? ? Underscore -???????? ? ?? ??????? Variable Name ?? ????????? ??????? ???????????? -??????????????????? Keyword ? Keyword ???????? ? Array for return break function sizeof case goto if constants switch continue labels pointer union ??????????????????? ?????????????????????????? ? -total$ : (Illegal character $) ??????????????? $ -2nd_sums : (Begin with a digit) ???????????????????????? -second sum : (Cannot use blank as a character) ????????????? -Total-Cars : (Illegal character -) ??????????????????? ¡°-¡± ????????????? Output ???????????????? ??????? Printf(); Fucntion ???????? Formation Control Data Type ??????????? ???????????????????? ? Quantity Data Type %d, %i Integer (int) ???????? %c Single character (char) ???????????? %s Character string (char) ?????????????? %f Fractional number (float) ??????????? %lf Double fractional number (double) ??????????? %ld Long Integer (long) ???????? ?.?.???????????? ????????????????????? ????????????? ?????????????????????????????????? ? ???????????? ??? ???????????????????????? ??????????????????????? ? ??????????????????????????? ? Ex. int a,b,sum; float c; ??????????????? ??????????????????????????? ?????????????? ???????????? ? Ex char c = ?A?; int i = 0; int k = i + 1;
  • 8. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.?.???????????????? 1. Arithmetic Operator: ???? Operator ???????? ?????????????????????????????????????????? ?????? Program .? Arithmetic Operator ???? Operator Meaning + Addition - Subtraction * Multiplication / Division % Modulus [remainder of an integer division.] Arithmetic Operator ???????? ? ???? ??? ??? ???? ?????????????????????????????????? ???? ????????????? Modulus ???????????????????????????????????? ? ??????? int a=1; int b=6; int c= a+b; 2 ¨C Relational and Equality Operator: ?????????????????????????????????????????????????? ????????????????? ???????????????????? ??????? Loop Statement , if-else Staement ,.....? Relational and Equality Operator ???????? ? < ?????? ( Less than ) <= ???????????? ( Less than or Equal ) >????? ( Greater than ) >= ??????????? ( Greater than or Equal ) == ????? !=???????? 3 ¨C Logical Operator: ????????? ?????????????????? ?????? ????????? Logical Operator ???????? ? && ?? ????? || ?? ??? 4. Increment and Decrement Operator : ???????? C ????????????????????????????????????? ???????????????????? ( Increment ) ??? ???? ( Decrementing ) ????????????? ? ????????? Increment (++) ??????????????? ??????????????????? ? ????????? Decrement (--) ??????????????? ??????????????????? ? ???????????????????????????????????????????????? ?? ? ?????????????? Constant ????????? ? ??????????????????????????? ?????????????????????? (++n)????? ????????????????? ( n++)? ????? ???? -(++n) ??????????????????????????? ( Ex. n=5 , x=++n , ???????? x=6 ) -(n++)???????????????????????????? ( Ex. x=n++, x=5, n=6) ]TahrN_2?
  • 9. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? #include<stdio.h> main ( ) { int a = 5; int b = 5; printf( ¡°Value of a: %d and b: %dn¡±, a, b ); printf( ¡°Value of a: %dn¡±, ++a ); printf( ¡°Value of b: %dn¡±, b++ ); getch(); return ( 0 ); } RbmaNviFI Prefix nig Postfix nwgdUcK?aenAeBlEdleyIgeRbIvaEt?g 5. Assignment operator: eKmanRbmaNvIFImYycMnYneTotenAelIRbmaNviFIFm?ta EdleKeRbIsMrab; Assigned (=) [ep?rtM¨¦l]b¡èKNnakenSamepSg?.RbmaNviFIenHKW ? Operator Simple Equal Meaning += a+=b a = a + b a ???????? b ? ?? a ???????????? -= a-=b a = a ¨C b a ??????? b ? ?? a ???????????? *= a*=b a = a * b a ?? ????? b? ??a ???????????? /= a/=b a = a / b a ???????? b ? ?? a ???????????? %= a=b%b a = a % b a ??????? b ? ?? a ???????? ?????????????? a ??? b ]TahrN_3 ? #include<stdio.h> main ( ) { int a = 1; int b = 5; printf( ¡°Value of a: %d and b: %dn¡±, a, b ); a += b; printf( ¡°Value of a: %dn¡±, a ); b %= 3; printf( ¡°Value of b: %dn¡±, b ); b *= a + 1; printf( ¡°Value of b: %dn¡±, b ); b /= a - 1; printf( ¡°Value of b: %dn¡±, b ); getch(); return ( 0 ); } ?????? ? ???????? ??? Output ??? Program ???????? ? 1. ?????????????????????????? ? -???????????????????? ( S=a*b) -?????????? S=a+b+d+d -?????????????????? S=a*a
  • 10. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? & ???????? ? ? Control Structure ' &' ?.?.If Statement ?????? Expression ??? (Expression ??????????????????? ) Statement ?????????????? ??????????? ????? ??? Expression ?????? ( Expression ???????????????? ) ????????????? Statement 2 ? ???????????? C Programing Statement ????????????? ??????????? Semicolon ¡° ; ¡± ?????????? Block Statement ????? ????????????? Braces ¡°{???}¡± ????????????????? ? ??????? if Statement ??? Syntax ??????????? ? Syntax1: Syntax2: ??????? ? ? #include<stdio.h> main( ) { int x; clrscr( ); printf( ¡°Input x:¡± ); scanf( ¡°%d¡±, &x ); if ( x == 10 ) { printf( ¡°n This is a good student.¡± ); } return ( 0 ); } ??????? ? ? #include<stdio.h> #include<stdlib> main( ) { int magic, guess; printf( ¡°nPlease input Guess value: ¡° ); scanf( ¡°%d¡±, &guess ); magic = rand( ); if ( guess == magic ) printf( ¡°n You are right.¡± ); if ( guess < magic ) printf( ¡°n You are too low.¡± ); if ( guess > magic ) printf( ¡°n You are too high.¡± ); printf( ¡°n %d is the magic value¡±, magic ); getch( ); return 0; } if(expression )Statement; Statement2; if(expression ){ Statement1; Statement2; .......... .......... }
  • 11. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.?.If ¨Celse Statement ???????? Expression ??? Statement 1 ?????????????? ????? Statement ????????? Statement2 ??????????? ? ?????? : ???????? ? ? ???????? ? ? if(expression ){ Statement1; } else} Statement2; } ??????????? #include<stdio.h> #include<conio.h> main( ) { if (result >= 45){ printf("Passn"); } else{ printf("Failn"); getch(); } } ???????????????? ? #include<conio.h> #include<math.h> void main(){ clrscr(); int a,b,c; float Deta,x1,x2; printf("Input A="); scanf("%d",&a); printf("Input B="); scanf("%d",&b); printf("Input C="); scanf("%d",&c); Deta=(pow(b,2)-(4*a*c)); if(Deta==0){ x1=x2=(-b/(2*a)); printf("x1=x2=%0.2fn",x1); } else if(Deta<0) printf("No rootn"); else{ x1=(-b-sqrt(Deta))/(2*a); x2=(-b+sqrt(Deta))/(2*a); printf("X1 is=%0.1fn",x1); printf("X2 is=%0.1fn",x2); } getch(); }
  • 12. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ???????? ? ? ?????????????????????????????????????????????????????? 1¡­Book [ -????????????????? ?? ???? ???????????? -?????????????????? ?? ??? ?? ???? ????????? ? % -?????????????????? ?? ??? ?? ???? ????????? ?? % ] 2¡­Pen [ -?????????????? ?? ???? ???????????? -??????????????? ?? ??? ?? ???? ????????? ? % -??????????????? ?? ??? ?? ???? ????????? ?? % ] 2¡­Ruler [ -?????????? ??????? ?? ???? ???????????? -?????????? ???????? ?? ??? ?? ???? ????????? ? % -?????????? ???????? ?? ??? ?? ???? ????????? ?? % ] #include<stdio.h> #include<conio.h> #include<process.h> void main(){ Again: clrscr(); int book,pen,ruler,U_price; float t_book,t_pen,t_ruler,t_all; char ch; gotoxy(33,2); textbackground(GREEN); textcolor(RED); cprintf(" THINKING MONEY "); //BOOK gotoxy(27,4); printf("Input Qauntity Book: "); scanf("%d",&book); gotoxy(27,5); printf("Input unit price : "); scanf("%d",&U_price); if(book<=15){ t_book=book*U_price; gotoxy(25,6); textcolor(YELLOW); cprintf("You have to pay = %0.1f Rilen",t_book); } if(book>15 && book<=30){ t_book=(book*95/100)*U_price; gotoxy(25,6); textcolor(YELLOW); cprintf("You have to pay = %0.1f Rilen",t_book); } if(book>30 && book<=60){ t_book=(book*90/100)*U_price; gotoxy(25,6); textcolor(YELLOW); cprintf("You have to pay = %0.1f Rilen",t_book); }
  • 13. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? //PEN gotoxy(27,8); printf("Input Qauntity Pen : "); scanf("%d",&pen); gotoxy(27,9); printf("Input unit price : "); scanf("%d",&U_price); if(pen<=15){ t_pen=pen*U_price; gotoxy(25,10); textcolor(YELLOW); cprintf("You have to pay =%0.1f Rilen",t_pen); } if(pen>15 && pen<=30){ t_pen=(pen*95/100)*U_price; textcolor(YELLOW); gotoxy(25,10); cprintf("You have to pay = %0.1f Rilen",t_pen); } if(pen>30 && pen<=60){ t_pen=(pen*90/100)*U_price; textcolor(YELLOW); gotoxy(25,10); cprintf("You have to pay = %0.1f Rilen",t_pen); } //Ruler gotoxy(27,16); printf("Input Qauntity Ruler : "); scanf("%d",&ruler); gotoxy(27,17); printf("Input unit price : "); scanf("%d",&U_price); if(ruler<=15){ t_ruler=ruler*U_price; textcolor(YELLOW); gotoxy(25,18); cprintf("You have to pay = %0.1f Rilen",t_ruler); } if(ruler>15 && pencil<=30){ t_ruler=(ruler*95/100)*U_price; textcolor(YELLOW); gotoxy(25,18); cprintf("You have to pay = %0.1f Rilen",t_ruler); } if(ruler>30 && ruler<=60){ t_ruler=(ruler*90/100)*U_price; textcolor(YELLOW); gotoxy(25,18); cprintf("You have to pay = %0.1f Rilen",t_ruler); } t_all=t_book+t_pen+t_ruler; textcolor(YELLOW); gotoxy(25,20); cprintf("TOTAL All TO PAY = %0.1f Rile",t_all); gotoxy(31,24); textcolor(YELLOW+GREEN); cprintf("Continue Program (Y/N)?"); fflush(stdin); ch=getchar(); if(ch=='Y' || ch=='y') goto Again; if(ch=='N' || ch=='n') exit(1); }
  • 14. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.?.If ¨Celse ¨Cif Statement if ¨C else_if Statement : ????????????????? if-else statement ??????????????????????????????????? ???? ????? ( ?????? ? ) ???????????????? if-else-if Statement ??????????? ? ?????? : ??????? ? ? ????? ? Message ??????? ? ??? ??????????????? ? ??? if ( expression 1) statement 1; else if ( expression 2) statement 2; else if ( expression 3) statement 3; else if ( expression n-1) statement n-1; else statement n; } #include <iostream> #include<conio.h> int main(){ int age; scanf("%d",&age); if ( age < 100 ) { printf("You are pretty young!n"); } else if ( age == 100 ) { printf("You are oldn"); } else { printf("You are really oldn"); } }
  • 15. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ??????? ? ? ????????????????????? ??????? ? ? ?????????????????? ??????
  • 16. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.? .Switch Statement Switch Statement ????????????????????? if-else-if ??? ?????????? if-else-if Statement ??????????????????? Variable ???????? ???????? ? ???? ?????????? Switch Statement ?????????? ? ??????
  • 17. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? Ex 1. Ex 2. #include<stdio.h> #include<conio.h> void main(){ clrscr(); int n; printf("Input N="); scanf("%d",&n); switch(n){ case 1: printf("Number one"); break; case 2: printf("Number two"); break; case 3: printf("Number three"); break; case 4: printf("Number four"); break; default: printf("The Number biggest is=%d"); } getch(); }
  • 18. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.? .?????? ?. ???????? Outpute Code ???????? ? int x,y; x=6; y=1; if(x<2) printf(¡°%dn¡±,x); else printf(¡°%dn¡±,y); ?. ??????????????????????? -??????????????????????? Ax+b=0 -?????????????????????????? C ?????????????????????????????????????? ????????? ?????? ? -????????????????????? Switch ????????????????????????? &??????????? ?'
  • 19. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? & ???????? ? ? Loop Control Structure ' &' ???????????????? ???????????? ???????? ???? Repeat Statement ? ??? Block Statement ???????? ???????????? ???? Loop ? ?????????? C Loop ????? ????? ?? ? ?. While Loop Statement ?. do_while Loop Statement ?. For Loop Statement Loop ???????????? Instruction Computer ?????? ???????????????????? ??????????????? ?????????????????? Control Variable ??????? ? ?.? .While Loop Statement ??????? While Loop ???????????????? Expression ??????????? ????? Statement ???? While Loop ???????????????( Execute ) ???????????????????? Expression ??????? ????????????????? ????? Statement ? Block Statement ?????????? Execute ???? ??????? Expression ?????? ?
  • 20. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ??????? ? ?.? .Do-While- Loop Statement ??????? do While Loop ?? Execute ??? Statement ????????????? Loop ????????????????????? ???? Expression ? ????????????????????? Expression ??????? ????? Statement ?????? Execute ??? ????????????? ?? ????????????????????? Expression ?????? ?
  • 21. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ??????? ? ? ??????? ? ?
  • 22. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ??????? ? ? ?.? .For Loop Statement ???? For loop ??????????? ? ???????? ??????????????????????????????????? ???????? ? ?????????? ??????? ??????? Loop ????????????????? ? ?? ???????????? ? ????????????????????????????????? ? ???????? For Loop :
  • 23. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ??????? ? ? ????? ? ??????? ? ?
  • 24. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ??????? ? ? ????? ?
  • 25. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ??????? ? ? ?????????????? ??? ?????? ??????? ? ? ???????????????????? ? ?.? .Goto Statement ???????????????? ????? ? ??????????????? ????? Statement ??????????????? ? ??????????? Goto label identifier ??????? ?????????????????? Goto statement ?? Execute ??? Statement ????????? ??????? ? ????????????????
  • 26. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? &??????????? ?'
  • 27. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? & ???????? ? ? Function ' ?.? .??????????? ????????????????????? ??? ??????????? ? ??????????????????? ????????????? ?????????????? ?????????????????????????? ??????????? ? ??????????????????????? ????????????????????? ????? ????????????????????? ?????????????????? ??????????????????????????? ?????????????????? ???????????? ??????????????? Error ????????????????????? .? Function ???????? ? - sub prigram - ??????????????????????????????????? - ???????????????????????? Error ????????? - ???????????? Memory - ????????????????????? ????????????????? ?.? .????????? ???? Sub Program or Function ???????????? C ? C++ Function ????????????????? ??? ?? ? -Standard Library Function -Function ?????????????? Programmer 1¡­ Standard Library Function ????????????????????????????????????? ????? ???????? Computer ??????????? ? ????? Function ??????????????? ?????????? Header file ? Standard Library Fucntion ?????????????????? ? ????????????????? ? Printf , scanf , goto;
  • 28. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.? .Function Declaration ???????????? Function ???????????? Function ???????????? ? ??????????????????? ? ?? ????? Main() Fucntion ? ?????????????????????? Compiler ?? Code ???? Function Decleration ???????? ????? ? Function Declatation ?????????? ?????????? Semicolon (;) ?.? .??????? Call ??????? ??????????????? Call ??????? ??????????????????????????????????????? ? -? ?????????????????????? Main(): ????????????????????????? Local ?????? ?? ???????? ??????????? Function ???????????????? Main() ???????????????????????? ? -? ?????????????????????? Main(): ????????????????????????? External Function ?? ???? Function ??????????????????????????????????????????????????????? ? ?.? .Return Statement ?????? C program ???????????????????? Return Statement ?????? C program ?????????????? Function ?????????????? ? mian() Function ?????? ? return statement ????????????????????? ????? Execute ??????? Function ??????? ? ??????????? Function ??????????????? Reurn ?? ?
  • 29. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.? .?????? &??????????? ?'
  • 30. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? & ???????? ? ? Array ' ?.? ??????? Array ????????????? Variable ?????? Data type ????? ????????? ???????? ??????????????? Array ?? Variable 1 ??????????????????????????????? ???????????? ??????????????? ? -???????????????? Array ???? Index ???? Subscripts ????????????? ? ??? Index=0 ?????? ???? ????? n ?????? Index = n-1 -???????? Array ???????????????? ????????????? -Data type ???????????????? -Array_Name ??????? ?????? Array -Length ????????? ? ???????? Array Ex ? .
  • 31. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ????? Ex ? . ?????
  • 32. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.? Two Dimensional Array ???????? C ??????????????????????????? Array ??????? ( Two dimension arrays ) ???????????????? ?????????????? Array ???????? ? ??????? ? ????????? Array ??????????????????? ? float dr [4] [5]; ????? ???????? ?? Variable ??????? float ???????????????? ????????????????? ? ??????? dr[0][0] dr[0][1] dr[0][2] dr[0][3] dr[0][4] dr[1][0] dr[1][1] dr[1][2] dr[1][3] dr[1][4] dr[2][0] dr[2][1] dr[2][2] dr[2][3] dr[2][4] dr[3][0] dr[3][1] dr[3][2] dr[3][3] dr[3][4] ?.? Array and Function ????????????? Array ?????????? Int ?????? 10 ?????( Element) ?? Int(10)? ???????????????? ????? ?????? ? ???????? ?????????? Array ?????????????????? ? ????????????????????????????????? ?? ? ?????????????????? Parameter ?????? ? ???? Parameter ??????? Array ????????????????????????? ? ????????????????????? Function ??? Argument ???????? Array ???????? ?? ??????????? ? 1. void Array_Function ( int b[10]); 2. void Array_Function ( int b [ ], int n ) ????????? ( Call ) Function ??????????? ???????????????? 1. Array_Function(b) 2. Array_Function(b,n)
  • 33. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.? Array String ??????? C ?? ??????????????? String ?????????????????????? ? ???????????? C String ??????????? ????????? Array ??? Character ? ????????????? String ?????????????????????? ???????????? Memory Location ??????????? String ???? Array ??? Array ?????? Dimension ?????????????? ? Location ???? Memory ? ?????????? String ????????????????? ?????? Null (??n?) Charater ? ??????? Char str[10]=¡±Computer¡± ??????? ? ?.? ??????
  • 34. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?????????????????? ??????????????????????? &??????????? ?'
  • 35. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? & ???????? ? ? Pointer ' ?.? ??????? Pointer ??????????????????? ??????????????????????????????? ????????????? Address ???????????? ?????????????????????????? Pointer ??????????????????? Address ???????? ???????????? ??????????????? ????????? ???????????????????????????????? ? ?.? ?????????? Pointer ??????????????? Pointer ????????????????? ????? ?????????? ( * ) ?????????????? ? ??.
  • 36. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.? Pointer to Pointer ??????????? Pointer ?????????????????????? ???? ?????????????????????????? ?? Pointer ???????????? ????? Pointer ?????????????????????????????? ? ??????? ? ?.? Pointer to Function ??????? Pointer ????????????? Address ??????????????? ???????????? Adress ???????????? ? ??????????????????? ???????????? ??????? ? ? #include<stdio.h> #include<conio.h> void main() { clrscr(); int x = 10; int *a; int **b; int ***c; a = &x; b = &a; c = &b; printf("value of x = %dn",x); printf("value of x by using a = %dn",*a); printf("value of x by using b = %dn",**b); printf("value of x by using c = %dn",***c); getch(); } #include<stdio.h> #include<conio.h> void change(int,int*); void main() { clrscr(); int a = 10 , b = 20; printf("Before calling function.n"); printf("a = %d n",a); printf("b = %d n",b); change(a,&b); printf("After calling function.n"); printf("a = %d n",a); printf("b = %d n",b); getch(); } void change(int x,int *y) { x = x * 5; *y = *y + x; }
  • 37. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ??????? ? ? &??????????? ?' #include<stdio.h> #include<conio.h> int (*psum)(int,int); int sum(int,int); void main() { clrscr(); int a = 40 , b = 20 ; psum=&sum; printf("Result = %d",(*psum)(a,b)); getch(); } int sum(int m , int n) { int s; s = m + n ; return (s); }
  • 38. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? & ???????? ? ? File ' ?.? ??????? ????????? ? ????? ????????????????????????????????????? ??????? ??????????? ????? Hard Disk , Flash ?????? ? ????????????? C Program File ???? Byte ????????? ????????? ???? ?????? ?????????? ???????????????????? ?? Text File ??? Binary File ? ?.? ?????????? File ?.? ?????????? Text File ???? File ????????????????????????? Graphic Character ????????????????????? FIle ??????????? ???????????????????????????????? ? ???????? ???????? ? ????????????? File ???????????? File Pointer ????????????????????????? File ???????????? ???????????? ?????????? ? ?????????????? ??????? fopen() ? ?????? -FileName : ??????? ?????? File ?????? FileName ??? Execute ??????????????????? -Model : ???? String ????????????????????????????????????????????????????????? Mod ?????? r/rt ??? Text File ???????????????? , ????? ? FIle ????? error w/wt ??? Text File ?????????????????? , ????? ? FIle ?????????????? a/at ??? Text File ??????????????????,????? ? FIle?????????????? r+/r+t ??? Text File ??????????? ???????? ? ??????????w+/w+t a+/a+t fp=fopen(¡°FileName¡±,¡±Model¡±)
  • 39. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.?.? ???? File ?????????? ?????????????????????????????????????????????????????? file ??? ? ??????? putc(), fputc(); ??????????????????????? ????????????????????????? File ????? File Pointer ? #include<stdio.h> #include<conio.h> void main() { clrscr(); char ch; FILE *fp; fp=fopen("Test1.txt","w"); if(fp==NULL) printf("Opening file was Error"); else { printf("Input character store infile.n"); printf("Press <Esc to stop>n"); do { ch=getch(); if(ch!=27) { putchar(ch); fputc(ch,fp); } } while(ch!=27); } fclose(fp); }
  • 40. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.?.? ???? File ????????? ???????????????????????????????????????????????????? file ??? ? ??????? getc(), fgetc(); ????????????????????????????????????????????? File ????? File Pointer ? #include<stdio.h> #include<conio.h> void main() { clrscr(); char ch; FILE *fp; fp=fopen("Test1.txt","r"); if(fp==NULL) printf("Opening file was Error."); else { printf("Read data from Filen"); ch=getc(fp); while(ch!=EOF) { putchar(ch); ch=getc(fp); } } fclose(fp); getch(); }
  • 41. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.?.? ???? Text File ?????????????????? ?????????????????????????????????????????????????????? file ??? ? ??????? putc(), fputc(); ??????????????????????????????????????????????? File ????? File Pointer ? #include<stdio.h> #include<conio.h> void main() { clrscr(); char ch; FILE *fp; fp=fopen("Test1.txt","a"); if(fp==NULL) printf("Opening file was Error"); else { printf("Input character to append in file.n"); printf("Press <Esc to stop>n"); do { ch=getch(); if(ch!=27) { putchar(ch); fputc(ch,fp); } }while(ch!=27); } fclose(fp); }
  • 42. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ????????????????? ?.? Binary File Binary File ??????????????????????? Internal Format ????????????????????? File ????????????? ????????????????? int , long , double , float ?????? ? ??????????? ???????? ? ????????????? File ????????? ??? Text File ??? ???????????????? mode ?????? ? &??????????? ?'
  • 43. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ?????????????????
  • 44. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ?????????????????
  • 45. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ?????????????????
  • 46. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ?????????????????
  • 47. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ?????????????????
  • 48. www.kompongsom4u.blogspot.com IT Book C Programming ?????????? 070 908 739 ?????????????????