SlideShare a Scribd company logo
1 of 34
Download to read offline
Week1 ; การใช้ภาษาซีเบื้องต้น
1.ไปที่โปรแกรม Dev C++
2.แล้วกดCtrl+n เพื่อเพิ่มการทางานของหน้าจอ
3.แล้วพิมพ์โค้ดในลักษณะนี้ค่ะ
#include <stdio.h>
void main()
{ printf("Miss.Paphaphin Kaewroeng n
ID:59170232 n Hello GI"); getch();
}
4. แล้วกดcompile&run หรือกดแป้นพิมพ์F11
Week2 cal
1.ไปที่โปรแกรม Dev C++
2.กด Ctrl+n เพื่อเพิ่มหน้าจอการทางาน
3.แล้วพิมพ์โค้ดในลักษณะนี้ค่ะ
#include "stdio.h" void main() {
int num1,num2,sum;
printf("please insert number1:");
scanf("%d",&num1);
printf("please insert number2:");
scanf("%d",&num2); sum =
num1 + num2; printf("Sum of
%d + %d =
%d",num1,num2,sum);
getch();
return 0; }
4.แล้วกด compile&run หรือกดแป้นพิมพ์F11
ใส่ตัวเลข 5 และ 6 จะได้ผลลพธ์ตามรูป
Week3_trapezoid
1. ไปที่โปรแกรม Dev C++
2. กด Ctrl+n เพื่อเพิ่มหน้าจอการทางาน
3. แล้วพิมพ์โค้ดในลักษณะนี้
การหาพื้นที่สี่เหลี่ยมคางหมูมีสูตรดังนี้
ผลบวกของด้านคู่ขนาน สูง
กาหนด w1,w2 = ผลบวกของ
ด้านคู่ขนาน
h = ความสูง
area = พื้นที่ทั้งหมด 0.5×(w1+w2) ×h
*1/2=0.5
#include <stdio.h> void
main()
{
float w1,w2,h,area; *float ใช้กับทศนิยม(7ตาแหน่ง)
printf("Please insret side1:"); scanf("%f",&w1); printf("Please insret side2:");
scanf("%f",&w2); printf("Please insert to Height:"); scanf("%f",&h); area = 0.5 *
(w1 + w2) * h; printf("Area of tranpezoid side1:%f side:2%f and Height:%f is
Area:%f",w1,w2,h,area); getch(); return 0;
}
4. 4.แล้วกด compile&run หรือกดแป้นพิมพ์F11
ใส่ตัวเลขที่ต้องการหาค่าแล้วกด Enter ก็จะคานวณผลออกมา
Week4_counting char
เป็นการนับตัวอักษรตามที่ได้พิมพ์ลงไป โดยจะมี
#include "string.h" , char name[30]; และ strlen(name)); เป็นตัวบ่งบอก
1.เปิดโปรแกรมDevC++ แลว้Ctrl+n เพื่อเพิ่มหน้าโปรเจคใหม่
2. แล้วพิมพ์โค้ดในลักษณะนี้
#include "stdio.h"
#include "string.h"
ข้อความ void main()
{
char name[30]; *char ใช้กับตัวอักษร 1 ตัว
printf("Please insert your name-surname:"); gets(name); printf("%s has %d character"
,name,strlen(name)); getch(); return 0;
}
ฟังก์ชัน จัดการข้อความรวม
3.แล้วกด compile&run หรือกดแป้นพิมพ์ F11 ให้ใส่ชื่อหรือประโยคที่ต้องการนับ
ตัวอักษรษรลงไปแล้วกด Enter ก็จะแสดงผลดังรูป
Week4_triangle
1.เข้าโปรแกรมDevC++ แลว้พิมพ์Ctrl+nเพื่อเพิ่มโปรเจคใหม่
2.เมื่อได้หน้าโปรเจคใหม่แล้วให้วิเคราะห์โจทย์ที่ได้มา คือ การหาพื้นที่สามเหลี่ยม โดยในการหาพื้นที่ครั้ง
นี้เราสามารถป้อนข้อมูลที่เป็นจุดทศนิยมได้ และคาตอบที่ได้จะเป็นจุดทศนิยมเช่นกัน
3.พิมพ์ภาษาซีลงไปในหน้าโปรเจคนี้
#include <stdio.h> void main ()
{
float b,h,area; * floatจะใช้กับตัวเลขที่มีการหาทศนิยม
printf("please insert Base of triangle:"); scanf("%f",&b); printf("please insert height of
triangle:"); scanf("%f",&h); area = 0.5 * b * h; printf("Area of triangle base:%f and
height:%f area is %.2f",b,h,area); getch(); return 0;
}
4.แล้วกด compile&run หรือกดแป้นพิมพ์ F11 จะได้ผลลัพธ์ดังรูปภาพ
ซึ่งในรูปภาพนี้ได้มีการพิมพ์ตัวเลขเพื่อคานวณหาพื้นที่แล้ว
Week5_age
เป็นการถามอายุ ถ้ามากกว่า 60 จะโชว์ข้อความ You are Oldest!!! แต่
ถ้าอายุไม่ถึง 60 จะโชว์ข้อความ You are baby face :P
1.เข้าโปรแกรมDevC++ แล้วกด Ctrl+n เพื่อเพิ่มหน้าโปรเจคใหม่
2.แล้วพิมพ์โค้ดในลักษณะนี้
#include "stdio.h" void
main() { int age;
printf("How old are you:");
scanf("%d",&age); if(age
>= 60)
{
printf("You are Oldest!!!naa");
}
else
{
printf("You are baby face :Pnaa");
}
printf("Good Bye");
getch();
return 0;
}
3.แล้วกด compile&run หรือกดแป้นพิมพ์ F11
Week5_char input
เป็นการบวกกนของตัวอักษรโดยใช้ค่าจากรหัส ASCII โดยในครั้งนี้เราจะ
กาหนดตัวอักษรเอง โดยการ input ข้อมูลเข้าไป
1.เข้าโปรแกรมDevC++ แล้วกด Ctrl+n เพื่อเพิ่มหน้าโปรเจคใหม่
2.แล้วพิมพ์โค้ดในลักษณะนี้
#include "stdio.h" void main() { char ch1,ch2;
printf("Please insert Character1:"); scanf("
%c",&ch1); printf("Please insert Character2:");
scanf(" %c",&ch2); printf("ch1:%d + ch2:%d =
%d",ch1,ch2,ch1+ch2); if(ch2 > ch1)
{
printf("nCh2 more than ch1");
}
printf("nGoodBye");
getch();
return 0;
}
3.แล้วกด compile&run หรือกดแป้นพิมพ์ F11
Week5_char
เป็นการหาค่าตัวอักษรจากรหัส ASCII แล้วนามาบวกกันโดยในครั้งนี้ใช้
ตัว g กับตัว k
1.เข้าโปรแกรมDevC++ แล้วกด Ctrl+n เพื่อเพิ่มหน้าโปรเจคใหม่
2.แล้วพิมพ์โค้ดในลักษณะนี้
#include "stdio.h" void main () { char ch1='g';
char ch2='k'; printf("ch1:%d + ch2:%d=
%d",ch1,ch2,ch1+ch2); if(ch2 > ch1)
{
printf("nch2 more than ch1");
}
printf("nGoodBye");
getch(); return 0;
}
สังเกต จะไม่มีเซมิโคลอน(;)
3.แล้วกดcompile&run หรือกดแป้นพิมพ์ F11
Week6_Grade
เป็นการใช้ฟังก์ชัน if else เลือกอย่างใดอย่างหนึ่ง เป็นการ
คานวณหาค่าเกรดเฉลี่ยโดยได้มีการกาหนดให้
A = (score>=80)
B+ =((score >=75)&&(score <=79))
B =((score >=70)&&(score <=74))
C+ =((score >=65)&&(score <=69))
C =((score >=60)&&(score <=64))
D+ =((score >=55)&&(score <=59)) D
=((score >=50)&&(score <=54))
แต่ถ้าได้น้อยกว่าที่กาหนดให้คือ F
1.เข้าโปรแกรมDevC++ แล้วกดCtrl+n เพื่อเพิ่มหน้าโปรเจคใหม่
2.แล้วพิมพ์โค้ดในลักษณะนี้
#include "stdio.h" void main() {
int score; printf("Please insert
your score:");
scanf("%d",&score);
if(score>=80)
printf("You are Grade A"); else
if ((score >=75)&&(score <=79))
printf("You are Grade B+"); else if
((score >=70)&&(score <=74))
printf("You are Grade B"); else if
((score >=65)&&(score <=69))
printf("You are Grade C+"); else if
((score >=60)&&(score <=64))
printf("You are Grade C"); else if
((score >=55)&&(score <=59))
printf("You are Grade D+"); else if
((score >=50)&&(score <=54))
printf("You are Grade D"); else
printf("You are Grade F");
printf("nGoodBye"); getch();
return 0; }
3.แล้วกด compile&run หรือกดแป้นพิมพ์F11
Week6_switch case for
รูปแบบของ switch case ดังนี้
switch(variable)
{ case contants:
statement;
break;
case contants_2;
break;
default:statement;
}
For คือ การทา ซ้า หรือวนลูป การ
ทา ซ้าจนกว่าจะครบตัวแปรตามที่ตั้งไว้
เป็นการสั่งอาหารแบบสั่งได้หลายเมนูโดยพิมพ์ตามที่กาหนดก็จะขึ้นรายชื่ออาหารและราคา
1.เข้าโปรแกรมDevC++ แล้วกดCtrl+n เพื่อเพิ่มหน้า โปรเจคใหม่
2.แล้วพิมพ์โค้ดในลักษณะนี้
#include "stdio.h" void main() { char
menu; int counter; for(counter=1 ;
counter <5 ; counter++)
{
printf("You want to Order:");
scanf(" %c",&menu); switch(menu)
{
case 'p' : printf("Papaya Salad 120n");
break; case 'c' : printf("Chicken Grill 500n");
break; case 't' : printf("Tomyam bone young
180n"); break; case 's' : printf("Sticky
rice 90n"); break;
default : printf("nTry again");
}
} printf("n------------------------
---"); getch(); return 0;
}
3.แล้วกด compile&run หรือกดแป้นพิมพ์F11
Week6_switch case
รูปแบบของ switch case ดังนี้
switch(variable)
{
case contants: statement;
break;
case contants_2; break;
default:statement;
}
ในที่นี้เป็นการให้เลือกสั่งอาหารโดยพิมพ์ตามที่กาหนดจะขึ้นเมนูและค่าอาหาร
1.เข้าโปรแกรมDevC++ แล้ว Ctrl+n เพื่อเพิ่มหน้าโปรเจคใหม่
2.แล้วพิมพ์โค้ด
ในลักษณะนี้
#include "stdio.h"
void main() {
char menu;
printf("You want
to Order:");
scanf("
%c",&menu);
switch(menu)
{
case 'p' : printf("Papaya Salad 120");
break; case 'c' : printf("Chicken Grill 500");
break; case 't' : printf("Tomyam bone young
180"); break; case 's' : printf("Sticky
rice 90"); break; default :
printf("nTry again");
} printf("n------------------------
---"); getch(); return 0;
}
3.แล้วกด compile&run หรือกดแป้นพิมพ์F11
Week7_sudkoon while
While เป็นการทา งานซ้าโดยตรวจสอบเงื่อนไขก่อน เป็นจริงจะ
ทา ซ้าแล้วจะวนจนเป็นเงื่อนไขเท็จ
เป็นการแสดงแม่สูตรคูณแบบพื้นฐานเริ่มต้นที่แม่2
1.เข้าโปรแกรมDevC++ แล้ว Ctrl+n เพื่อเพิ่มหน้าโปรเจคใหม่
2. แล้วพิมพ์โค้ดใน
ลักษณะนี้
#include "stdio.h" void
main() { int
counter; counter=1;
while(counter<=12)
{
printf("2 x %d = %dn",counter,2 * counter);
counter++; } printf("nGoodBye"); getch();
return 0;
}
3.แล้วกด compile&run หรือกดแป้นพิมพ์F11
Week7_sudkoon
เป็นการแสดงแม่สูตรคูณตามที่เราได้กาหนดลงไป ได้หลายๆรอบ
1.เข้าโปรแกรมDevC++แล้ว Ctrl+n เพื่อเพิ่มหน้าโปรเจคใหม่
2. แล้วพิมพ์โค้ดในลักษณะนี้
#include "stdio.h" void main() { int
counter,number,counter1;
for(counter1=1;counter1<=5;counter1++)
{
printf("Please insert Number:");
scanf("%d",&number);
for(counter=1;counter<=12;counter++)
{
printf("%d x %d =%dn",number,counter,number * counter);
}
}
printf("nGoodBye")
; getch(); return 0;
}
3.แล้วกด compile&run หรือกดแป้นพิมพ์F11
Week8_arrey1D
อาเรย์(arrey) เป็นการเก็บค่าเยอะๆไว้ในตัวเดียว
อาเรย์1มิติ
Ex. int a=5;
int a[5];
**a เก็บสมาชิกได้5 ตัว
1.เข้าโปรแกรมDevC++ แล้ว Ctrl+n เพื่อเพิ่มหน้าโปรเจคใหม่
2.แล้วพิมพ์โค้ด
ในลักษณะนี้
#include
"stdio.h" void
main() { int
a[5]; a[0] = 1;
a[1] = 2; a[2] = 3;
a[3] = 4; a[4] = 5;
printf("%d %d
%d %d
%d",a[0],a[1],a[2
],a[3],a[4]);
printf("nGoodBy
e"); getch();
return 0;
}
3.แล้วกด compile&run หรือกดแป้นพิมพ์ F11
Week8_arrey2D crosstab
อาเรย์2 มิติ
เก็บข้อมูลเป็นห้อง
int a {5,5]; ๆ
1.เข้าโปรแกรมDevC++ แล้ว Ctrl+n เพื่อเพิ่มหน้าโปรเจคใหม่
2.แล้วพิมพ์โค้ดใน
ลักษณะนี้
#include "stdio.h"
void main() { int
table[9][9],i,j,x;
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{ x
= i-1; table[x][j-
1]= i*j; }
}
printf("* |t1t2t3t4t5t6t7t8t9n"); printf("-----------------------------------------------
---------------------------n"); for(i=0;i<9;i++)
{ printf("%d |t",i+1);
for(j=0;j<9;j++)
{
printf("%dt",table[i][j]);
}
}
getch();
return 0;
}
3แล้วกด .compile&run หรือกดแป้นพิมพ์ F11
Week8_arrey reverse
เป็นการกลับตัวอักษรในคาหรือประโยค (นับถอยหลัง)
1.เข้าโปรแกรมDevC++ แล้วกด Ctrl+n เพื่อเพิ่มหน้า โปรเจคใหม่
2.แล้วพิมพ์โค้ดในลักษณะนี้
#include "stdio.h"
#include "conio.h"
#define MAX_VALUE 50
void main()
{
int i;
char word[MAX_VALUE];
printf("Enter Your Word");
gets(word); printf("Reverse of
your word is");
for(i=strlen(word)-1;i>=0;i--)
{
printf("%c",word[i]);
}
getch();
return 0; }
3.แล้วกด compile&run หรือกดแป้นพิมพ์F11

More Related Content

Viewers also liked

12 ge lecture presentation
12 ge lecture presentation12 ge lecture presentation
12 ge lecture presentation
mahmood jassim
 
De toana ct_dh_k11
De toana ct_dh_k11De toana ct_dh_k11
De toana ct_dh_k11
Duy Duy
 
19 ge dna tech lecture presentation
19 ge dna tech lecture presentation19 ge dna tech lecture presentation
19 ge dna tech lecture presentation
mahmood jassim
 
Bioinspired Character Animations: A Mechanistic and Cognitive View
Bioinspired Character Animations: A Mechanistic and Cognitive ViewBioinspired Character Animations: A Mechanistic and Cognitive View
Bioinspired Character Animations: A Mechanistic and Cognitive View
Simpson Count
 

Viewers also liked (20)

นายกิติกร เพชรคง
นายกิติกร เพชรคง นายกิติกร เพชรคง
นายกิติกร เพชรคง
 
English G. Karimzadeh's CV-23
English G. Karimzadeh's CV-23English G. Karimzadeh's CV-23
English G. Karimzadeh's CV-23
 
นางสาววิภาวี ยอดชัยภูมิ
นางสาววิภาวี ยอดชัยภูมินางสาววิภาวี ยอดชัยภูมิ
นางสาววิภาวี ยอดชัยภูมิ
 
นางสาวพิชญ์สิณี ศรีไพศาลสุข
นางสาวพิชญ์สิณี ศรีไพศาลสุขนางสาวพิชญ์สิณี ศรีไพศาลสุข
นางสาวพิชญ์สิณี ศรีไพศาลสุข
 
12 ge lecture presentation
12 ge lecture presentation12 ge lecture presentation
12 ge lecture presentation
 
Turn the light on digital landscape
Turn the light on digital landscapeTurn the light on digital landscape
Turn the light on digital landscape
 
OTIMIZAÇÃO PARA MECANISMOS DE BUSCA (SEO), MARKETING PARA FERRAMENTAS DE BUSC...
OTIMIZAÇÃO PARA MECANISMOS DE BUSCA (SEO), MARKETING PARA FERRAMENTAS DE BUSC...OTIMIZAÇÃO PARA MECANISMOS DE BUSCA (SEO), MARKETING PARA FERRAMENTAS DE BUSC...
OTIMIZAÇÃO PARA MECANISMOS DE BUSCA (SEO), MARKETING PARA FERRAMENTAS DE BUSC...
 
Christmas decorations
Christmas decorationsChristmas decorations
Christmas decorations
 
Maine keynote 2015
Maine keynote 2015Maine keynote 2015
Maine keynote 2015
 
C4Q
C4QC4Q
C4Q
 
FBSIC - Memo
FBSIC - MemoFBSIC - Memo
FBSIC - Memo
 
Proyecto agua
Proyecto aguaProyecto agua
Proyecto agua
 
Tarea..1
Tarea..1Tarea..1
Tarea..1
 
Buckling Of Raker Piles
Buckling Of Raker Piles Buckling Of Raker Piles
Buckling Of Raker Piles
 
De toana ct_dh_k11
De toana ct_dh_k11De toana ct_dh_k11
De toana ct_dh_k11
 
Universal Design for Learning (UDL): Initial Outcomes of a Leadership Develop...
Universal Design for Learning (UDL): Initial Outcomes of a Leadership Develop...Universal Design for Learning (UDL): Initial Outcomes of a Leadership Develop...
Universal Design for Learning (UDL): Initial Outcomes of a Leadership Develop...
 
Το χρονικό των στοιχειωδών σωματιδίων Χιωτέλης Ιωάννης Γενικό Λύκειο Πελοπίου
Το χρονικό των στοιχειωδών σωματιδίων Χιωτέλης Ιωάννης Γενικό Λύκειο ΠελοπίουΤο χρονικό των στοιχειωδών σωματιδίων Χιωτέλης Ιωάννης Γενικό Λύκειο Πελοπίου
Το χρονικό των στοιχειωδών σωματιδίων Χιωτέλης Ιωάννης Γενικό Λύκειο Πελοπίου
 
Executive briefing supply chain academy v2015 11-nov
Executive briefing supply chain academy v2015 11-novExecutive briefing supply chain academy v2015 11-nov
Executive briefing supply chain academy v2015 11-nov
 
19 ge dna tech lecture presentation
19 ge dna tech lecture presentation19 ge dna tech lecture presentation
19 ge dna tech lecture presentation
 
Bioinspired Character Animations: A Mechanistic and Cognitive View
Bioinspired Character Animations: A Mechanistic and Cognitive ViewBioinspired Character Animations: A Mechanistic and Cognitive View
Bioinspired Character Animations: A Mechanistic and Cognitive View
 

Similar to นางสาวกัญญารัตน์ คิดในทางดี

Computer programming
Computer  programmingComputer  programming
Computer programming
Preaw Jariya
 
59170065 พัชริกา
59170065 พัชริกา59170065 พัชริกา
59170065 พัชริกา
Beam Suna
 
คอมพิวเตอร์โอลิมปิก
คอมพิวเตอร์โอลิมปิกคอมพิวเตอร์โอลิมปิก
คอมพิวเตอร์โอลิมปิก
Sumalee Sonamthiang
 
Slide unit1 พื้นฐานภาษาซี
Slide unit1  พื้นฐานภาษาซีSlide unit1  พื้นฐานภาษาซี
Slide unit1 พื้นฐานภาษาซี
Noonid Maehongson
 

Similar to นางสาวกัญญารัตน์ คิดในทางดี (20)

Computer programming
Computer  programmingComputer  programming
Computer programming
 
Computer programming
Computer programmingComputer programming
Computer programming
 
59170065 พัชริกา
59170065 พัชริกา59170065 พัชริกา
59170065 พัชริกา
 
การเขียนฟังก์ชั่นในภาษา C
การเขียนฟังก์ชั่นในภาษา Cการเขียนฟังก์ชั่นในภาษา C
การเขียนฟังก์ชั่นในภาษา C
 
C lang
C langC lang
C lang
 
Tec4
Tec4Tec4
Tec4
 
C language
C languageC language
C language
 
C language
C languageC language
C language
 
comproyui
comproyuicomproyui
comproyui
 
คอมพิวเตอร์โอลิมปิก
คอมพิวเตอร์โอลิมปิกคอมพิวเตอร์โอลิมปิก
คอมพิวเตอร์โอลิมปิก
 
Week5
Week5Week5
Week5
 
001-โปรแกรมภาษาซี
001-โปรแกรมภาษาซี001-โปรแกรมภาษาซี
001-โปรแกรมภาษาซี
 
59170109 ณัฐฐพล
59170109 ณัฐฐพล59170109 ณัฐฐพล
59170109 ณัฐฐพล
 
Slide unit1 พื้นฐานภาษาซี
Slide unit1  พื้นฐานภาษาซีSlide unit1  พื้นฐานภาษาซี
Slide unit1 พื้นฐานภาษาซี
 
นางสาวณัฐวดี ชุมสิงห์
นางสาวณัฐวดี ชุมสิงห์ นางสาวณัฐวดี ชุมสิงห์
นางสาวณัฐวดี ชุมสิงห์
 
Know3 4
Know3 4Know3 4
Know3 4
 
Week7
Week7Week7
Week7
 
capture 59170107 group 2
capture 59170107 group 2capture 59170107 group 2
capture 59170107 group 2
 
7 2โครงสร้าง
7 2โครงสร้าง7 2โครงสร้าง
7 2โครงสร้าง
 
05 loops
05 loops05 loops
05 loops
 

นางสาวกัญญารัตน์ คิดในทางดี