SlideShare uma empresa Scribd logo
1 de 56
Baixar para ler offline
Programming in Life
ComCamp 22 Programming Training
Session: 1-1
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
What is a Programming?
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
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
History programming
Timeline
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
Programming Skill
•Syntax
•Structure
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
C language = Backend
Command Line
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
Why C language?
•Easy
•Simple
•Root
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
Get Started
Tools Knowledge Time
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
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
Basic C
ComCamp 22 Programming Training
Session: 1-2
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
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
Basic C Concepts
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
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
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
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
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
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
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
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
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
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
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
Condition
ComCamp 22 Programming Training
Session: 1-3
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
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
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
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
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
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
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
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
Loop
ComCamp 22 Programming Training
Session: 2-1
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
What is Loop?
Loop = การวนซํ้า
ในการเขียนวนซํ้า
ทําให้ช่วยลดการ
เขียนโปรแกรมลงได้
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
Loop Function
While or Do While
For
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
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
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
Code
#include <stdio.h>
int main()
{
! int op, budget, amount;
printf("Insert your budget: ");
! scanf("%d", &budget);
! printf("1 Income, 2 expense, 0 Exit: ");
! scanf("%d", &op);
! while (op!=0) {
! ! if (op==1) {
! ! ! printf("Income amount: ");
! ! ! scanf("%d", &amount);
! ! ! budget = budget + amount;
! ! }
! ! else {
! ! ! printf("Expense amount: ");
! ! ! scanf("%d", &amount);
! ! ! budget = budget - amount;
! ! }
! ! printf("Your balance is %d", budget);
! ! printf("1 Income, 2 expense, 0 Exit: ");
scanf("%d", &op);
}
return 0;
}
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
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
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
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
Debug
ComCamp 22 Programming Training
Session: 2-2
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
What is Debug?
Debug = การแก้ไข
จุดผิดพลาดของ
โปรแกรม
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
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
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
Code#include <stdio.h>
int main()
{
! int op, budget, amount;
printf("Insert your budget: ");
! scanf("%d", &budget);
! printf("1 Income, 2 expense, 0 Exit: ");
! scanf("%d", &op);
! while (op!=0) {
! ! if (op==1) {
! ! ! printf("Income amount: ");
! ! ! scanf("%d", &amount);
! ! ! budget = budget + amount;
! ! }
! ! else if(op==2) {
! ! ! printf("Expense amount: ");
! ! ! scanf("%d", &amount);
! ! ! budget = budget - amount;
! ! }
else {
printf(“Please insert only(1,2,0)n”);
}
! ! printf("Your balance is %d", budget);
! ! printf("1 Income, 2 expense, 0 Exit: ");
scanf("%d", &op);
}
return 0;
} Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
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
Loop (continue)
ComCamp 22 Programming Training
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
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
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
• 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
Project Show Case
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
See U Soon At KMUTT :)
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010
Create by Chris
http://coffeemilkcrazy.wordpress.com/
Wednesday, March 31, 2010

Mais conteúdo relacionado

Semelhante a Programming in Life

Semelhante a Programming in Life (20)

Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
(ThoughtWorks Away Day 2009) one or two things you may not know about typesys...
 
Big Brother helps you
Big Brother helps youBig Brother helps you
Big Brother helps you
 
Tu1
Tu1Tu1
Tu1
 
Lab 1.pptx
Lab 1.pptxLab 1.pptx
Lab 1.pptx
 
C++17 not your father’s c++
C++17  not your father’s c++C++17  not your father’s c++
C++17 not your father’s c++
 
C++ L09-Classes Part2
C++ L09-Classes Part2C++ L09-Classes Part2
C++ L09-Classes Part2
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
c++ lab manual
c++ lab manualc++ lab manual
c++ lab manual
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
 
C language
C languageC language
C language
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
C programming day#3.
C programming day#3.C programming day#3.
C programming day#3.
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
Moving Average Filter in C
Moving Average Filter in CMoving Average Filter in C
Moving Average Filter in C
 
Design problem
Design problemDesign problem
Design problem
 

Último

Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 

Último (20)

Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 

Programming in Life

  • 1. Programming in Life ComCamp 22 Programming Training Session: 1-1 Create by Chris http://coffeemilkcrazy.wordpress.com/ Wednesday, March 31, 2010
  • 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
  • 5. History programming Timeline Create by Chris http://coffeemilkcrazy.wordpress.com/ Wednesday, March 31, 2010
  • 8. Programming Skill •Syntax •Structure Create by Chris http://coffeemilkcrazy.wordpress.com/ Wednesday, March 31, 2010
  • 9. C language = Backend Command Line Create by Chris http://coffeemilkcrazy.wordpress.com/ Wednesday, March 31, 2010
  • 10. Why C language? •Easy •Simple •Root 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
  • 39. Code #include <stdio.h> int main() { ! int op, budget, amount; printf("Insert your budget: "); ! scanf("%d", &budget); ! printf("1 Income, 2 expense, 0 Exit: "); ! scanf("%d", &op); ! while (op!=0) { ! ! if (op==1) { ! ! ! printf("Income amount: "); ! ! ! scanf("%d", &amount); ! ! ! budget = budget + amount; ! ! } ! ! else { ! ! ! printf("Expense amount: "); ! ! ! scanf("%d", &amount); ! ! ! budget = budget - amount; ! ! } ! ! printf("Your balance is %d", budget); ! ! printf("1 Income, 2 expense, 0 Exit: "); scanf("%d", &op); } return 0; } 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
  • 47. Code#include <stdio.h> int main() { ! int op, budget, amount; printf("Insert your budget: "); ! scanf("%d", &budget); ! printf("1 Income, 2 expense, 0 Exit: "); ! scanf("%d", &op); ! while (op!=0) { ! ! if (op==1) { ! ! ! printf("Income amount: "); ! ! ! scanf("%d", &amount); ! ! ! budget = budget + amount; ! ! } ! ! else if(op==2) { ! ! ! printf("Expense amount: "); ! ! ! scanf("%d", &amount); ! ! ! budget = budget - amount; ! ! } else { printf(“Please insert only(1,2,0)n”); } ! ! printf("Your balance is %d", budget); ! ! printf("1 Income, 2 expense, 0 Exit: "); scanf("%d", &op); } return 0; } 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