3. What is a Programming?
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
4. Once upon a time
• Augusta Lovelace Ada
คือ โปรแกรมเมอร์คน
แรกของโลก
• Edsger Wybe Dijkstra
ใช้คําว่า โปรแกรมเมอร์
(Programmer) กับโลก
ของคอมพิวเตอร์เป็น
คนแรกDo not try to change the world. Give the world the opportunity to change itself
Edsger Wybe Dijkstra เป็น theoretical physicist และเสียชีวิตด้วยโรคมะเร็ง 6 ส.ค. 2002 (อายุ 72 ปี)
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
11. Get Started
Tools Knowledge Time
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
12. Tools : Codeblocks
Create Project
(1) Open Codeblocks
(2) “File” > “New” > “Empty file”
(3) “Save” or “Save as” than name your project “myPrj”
(4) Format “C/C++ files”
At myPrj tab coder
(5) Paste “ “
(6) Build and run
#include <stdio.h>
main()
{
printf(“Hello, World!”);
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
13. Basic C
ComCamp 22 Programming Training
Session: 1-2
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
14. Basic C
A Simple C Program
This is your first C program. Paste this example into a plain text editor
and name the file test1.c
#include <stdio.h>
main()
{
printf(“We are ComCamp”);
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
15. Basic C Concepts
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
16. Header
Main Function
Basic C
A Simple C Program
This is your first C program. Paste this example into a plain text editor
and name the file test1.c
#include <stdio.h>
main()
{
printf(“We are ComCamp”);
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
17. Basic C
Typed Variable
In C, the rules are more strict.You have to declare the type of data a
variable will hold, and the type can't change later. Here's the C equivalent
of the snippet above:
int variable1 = 2;
float variable2 = 1.618;
char variable3 = 'A';
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
18. Basic C
Typed Functions
In C, you have to declare the type of data you plan to return from a
function.The return type can be any C variable type, and is placed to the
left of the function name.
int numberOfPeople ()
{
return 3;
}
float dollarsAndCents ()
{
return 10.33;
}
char firstLetter ()
{
return 'A';
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
19. Basic C
You can also specify the return type as void. For now, you can just think of
this as saying that no value will be returned:
void printHello ()
{
printf ("Hellon");
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
20. Basic C
Types for Parameters
It's also necessary to define types for values passed into a function. Unlike
scripting languages, though, you can't set default values.
int difference (int value1, int value2)
{
return value1 - value2;
}
float changeDue (float amountPaid, float costOfItem)
{
return amountPaid - costOfItem;
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
21. Basic C
Declaring Functions
In C, a function has to be declared before any other code can call it.You can
put all the functions before main(), but this quickly becomes a lot of work.
int difference ( int value1, int value2 );
float changeDue ( float amountPaid, float costOfItem );
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
22. Basic C
Header
Main Function
Declaring Sum Function
Sum Function
Example
Here's an example. Paste the contents into a file called test2.c
#include <stdio.h>
int sum ( int x, int y );
main ()
{
int theSum;
theSum = sum (10, 11);
printf ( "Sum: %in", theSum );
}
int sum ( int x, int y )
{
return x + y;
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
23. Basic C
In C, you can't embed variables directly inside text.You have to use a format
string with markers for the variables:
int var1 = 3;
int var2 = 8;
printf ("First value: %d second value: %d", var1, var2);
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
24. Basic C
Exercise 1, Say Hello
Step 1 : Paste “#include <stdio.h>” Header standard function.
Step 2 : Paste “main() {...}“ Main function for first run.
Step 3 : Insert “printf(“Hello We are ComCamp”);” Console show this log.
#include <stdio.h>
main()
{
printf(“Hello We are ComCamp”);
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
25. Basic C
Exercise 2, Say Hello Advance
Step 1 : Paste “#include <stdio.h>” Header standard function.
Step 2 : Paste “main() {...}” Main function for first run.
Step 3 : Insert “char name[10];” Into Main function, declare variable
Step 4 : Insert “printf (“What your name: ”);” printf Console show log.
Step 5 : Insert “scanf(“%s”, name);” scanf Console read user enter.
Step 6 : Insert “printf(“Hello %s, We are ComCamp”, name);”
#include <stdio.h>
main()
{
char name[10];
printf(“What your name: “);
scanf(“%s”, name);
printf(“Hello %s, We are ComCamp”, name);
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
26. Condition
ComCamp 22 Programming Training
Session: 1-3
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
27. What is Condition?
Programming = การกําหนดระบบ
และกลไกให้กับเครื่องคอมพิวเตอร์ได้
ประมวลผล
Condition = เงือนไข
Ex. x=2, x>0 is true or false
ในการเขียนโปรแกรมให้ซับซ้อนและ
ตัดสินได้ผ่านเงือนไขที่เรากําหนด จะ
ต้องใช้ if และ else
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
28. How to use
How to use if and else
syntax of if else function, if(condition) {statement} else{statement}
...
if(age>18)
{
printf(“You can pass”);
}
else
{
printf(“You can’t pass”);
}
...
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
29. If and Else Condition
Exercise 3, Dek ComCamp
Step 1 : Paste “#include <stdio.h>” Header standard function.
Step 2 : Paste “main() {...}” Main function for first run.
Step 3 : Insert “char ans;” Into Main function, declare variable
Step 4 : Insert “printf (“Are you hot (Y/N): ”);” printf Console show log.
Step 5 : Insert “scanf(“%c”, &ans);” scanf Console read user enter.
Step 6 : add condition if say “yes” program say “You are ComCamp!”
condition = (ans==’Y’)
#include <stdio.h>
int main()
{
char ans;
printf("Are you hot (Y/N): ");
scanf("%c", &ans);
if (ans=='Y') {
! ! printf("You are ComCamp!");
! }
return 0;
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
30. How to use
How to use else if Extend
systax of if else function, if(condition1) {statement1} else if(condition2)
{statement2} else{statement3}
...
if(age>=18 && age<=100)
{
printf(“You can pass”);
}
else if(age<18 && age>=0)
{
printf(“You can’t pass”);
}
else
{
printf(“Error you must enter 0-100”);
}
...
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
31. Condition
Exercise 3, Dek ComCamp Extend
Step 1 : Paste “#include <stdio.h>” Header standard function.
Step 2 : Paste “main() {...}” Main function for first run.
Step 3 : Insert “char ans;” Into Main function, declare variable
Step 4 : Insert “printf (“Are you hot (Y/N): ”);” printf Console show log.
Step 5 : Insert “scanf(“%c”, &ans);” scanf Console read user enter.
Step 6 : add condition if say “Y” program say “you are comCamp!”
condition = (ans==’Y’)
Step 7 : add condition else if say “N” program say “Oh!...You aren’t ComCamp!”
condition = (ans==’N’)
Step 8 : add else say notY and N program say “You must enter only (Y/N).”
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
32. Symbol of C
CONDITION
&& AND
|| OR
== EQUAL
!= NOT EQUAL
>= MORE THAN
OR EQUAL
<= LESS THAN
OR EQUAL
MATH
> MORE THAN
< LESS THAN
= SET VARIABLE
+ PLUS
- MINUS
* MULTIPLE
/ TIME
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
33. Code
#include <stdio.h>
int main()
{
char ans;
printf("Are you hot (Y/N): ");
scanf("%c", &ans);
if (ans=='Y')
{
! ! printf("You are ComCamp!");
! }
else if (ans==’N’)
{
printf("Oh!...You aren’t ComCamp!");
}
else
{
printf(“You must enter only (Y/N)”);
}
return 0;
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
34. Loop
ComCamp 22 Programming Training
Session: 2-1
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
35. What is Loop?
Loop = การวนซํ้า
ในการเขียนวนซํ้า
ทําให้ช่วยลดการ
เขียนโปรแกรมลงได้
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
36. Loop Function
While or Do While
For
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
37. What is While Loop?
How to use while loop
syntax of if While function, While(condition) {statement}
...
printf(“How old are you: “);
scanf(“%d”, &age);
while(age<18)
{
printf(“You can’t pass”);
printf(“How old are you: “);
scanf(“%d”, &age);
}
printf(“You can pass”);
...
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
38. While Loop
Exercise 4, Accounting
Step 1 : Paste “#include <stdio.h>” Header standard function.
Step 2 : Paste “main() {...}” Main function for first run.
Step 3 : Insert “int op; int budget; int amount;” Into Main function, declare variable
Step 4 : Insert “printf (“Insert your budget: ”);”
Step 5 : Insert “scanf(“%d”, &budget);”
Step 6 : Insert “printf (“1 Income, 2 expense,0 Exit: ”);”
Step 7 : Insert “scanf(“%d”, &op);” scanf Console read user enter.
Step 8 : Insert “while(op!=0) {...}” while loop
Step 9 : add condition if say “1” program ask “Income amount: ”
condition = (op==1) and scanf to receive Income amount than calculate formula:
budget = budget + amount;
Step 10 : else program say “Expanse amount:” and scanf to receive Expanse amount
than calculate formula: budget = budget - amount;
Step 11 : show budget and loop to menu again
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
40. What is Do While Loop?
How to use do while loop
syntax of if While function, do {statement}While(condition);
...
do
{
printf(“How old are you: “);
scanf(“%d”, &age);
if(age<18)
printf(“You can’t passn”);
} while(age<18);
printf(“You can pass”);
...
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
41. Do While Loop
Exercise 5, Login
Step 1 : Paste “#include <stdio.h>” Header standard function.
Step 2 : Paste “main() {...}” Main function for first run.
Step 3 : Insert “int pwd;” Into Main function, declare variable
Step 4 : Insert “do{...}”
Step 5 : Insert “printf (“Enter your password: ”);”
Step 6 : Insert “scanf(“%d”, &pwd);”
Step 7 : Insert “while(pwd!=0000);” 0000 is a password.
Step 8 : Insert “printf (“Password Correct!”);”
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
42. Code
#include <stdio.h>
int main()
{
! int pwd;
! do {
! ! printf("Enter your password: ");
! ! scanf("%d", &pwd);
! } while (pwd!=0000);
! printf("Password Correct!");
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
43. Debug
ComCamp 22 Programming Training
Session: 2-2
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
44. What is Debug?
Debug = การแก้ไข
จุดผิดพลาดของ
โปรแกรม
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
45. Debug
จากโปรแกรมที่แล้ว Exercise 4, Accounting ตรง
เมนูถ้าเลือก นอกเหนือจากตัวเลือกในเมนูแล้วเช่น ใส่
5 ไป โปรแกรมจะไปยัง รายจ่าย ซึ่งจริงๆแล้ว
โปรแกรมควรฟ้องว่า Error
Step 6 : Insert “printf (“1 Income, 2 expense,0 Exit: ”);”
Step 7 : Insert “scanf(“%d”, &op);” scanf Console read user enter.
Step 8 : Insert “while(op!=0) {...}” while loop
Step 9 : add condition if say “1” program ask “Income amount: ”
condition = (op=1) and scanf to receive than calculate
Step 10 : else program say “Expanse amount:”
and scanf to receive than calculate
Step 11 : show budget and loop to menu again
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
46. Debugging
Excercise 6, Debugging
Accounting Program โดยใช้ else if(...) {...}
Step 6 : Insert “printf (“1 Income, 2 expense,0 Exit: ”);”
Step 7 : Insert “scanf(“%d”, &op);” scanf Console read user enter.
Step 8 : Insert “while(op!=0) {...}” while loop
Step 9 : add condition if say “1” program ask “Income amount: ”
condition = (op==1) and scanf to receive than calculate
Step 10 : add condition else if say “2” program say “Expanse amount:”
condition = (op==2) and scanf to receive than calculate
Step 10.5 : else not say 1,2,0 program say “Please enter only (1,2,0)n”
Step 11 : show budget and loop to menu again
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
48. Debug Again
Excercise 7, Debugging Pro
เมื่อ User ใส่ค่าติดลบลงไป โปรแกรมจะต้องให้ใส่ค่า
ใหม่อีกครั้ง และแจ้งผู้ใช้ โดยใช้ while(budget<0)
{...}
while (budget<0)
{
! printf("Don't insert minus number.n");
! printf("Insert your budget: ");
! scanf("%d", &budget);
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
49. Loop (continue)
ComCamp 22 Programming Training
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
50. What is For Loop
How to use For loop
syntax of if For function, for(initial; condition; increment) {statements}
...
for(i=0;i<=12;i++)
{
printf(“2 x %d = %dn”, i, i*2);
}
...
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
51. For Loop
Excercise 8, Multiple
...
for(i=0;i<=12;i++)
{
printf(“%d x %d = %dn”, multi, i, i*multi);
}
...
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
52. • P’คริส krist_jarruspong@hotmail.com
http://coffeemilkcrazy.wordpress.com
• P’Flash cyztalzboyz@programmer.in.th <<
msn & mail
• P’เต้น chocolate_wizard@hotmail.com
• P’ดอย casio_961@hotmail.com
• P’บุ๊ง boong_getout@hotmail.com
• P’ฟิวส์ ofusezao@hotmail.com
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
53. Project Show Case
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
54. See U Soon At KMUTT :)
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010