รายละเอียดของรายวิชาpws.npru.ac.th/pongborworn/data/files/ตั๋ว... · Web view๕. ภาคการศ กษา / ช นป ท
หลักการเข...
Transcript of หลักการเข...
![Page 1: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/1.jpg)
หลกการเขยนโปรแกรม
ใ โป1. การวเคราะหปญหา
ขนตอนในการเขยนโปรแกรม
ประกอบดวย 5 ขนตอน คอ
ญ
องคประกอบของการวเคราะหงาน ประกอบดวย
1.1 ผลลพธ(Output) ตองมอวาโจทยหรองานทเราทา1. การวเคราะหปญหา
2. การกาหนดแผนในการแกปญหา
( p )
ตองการผลลพธอยางไร เพอตรวจสอบวาไดผลลพธไปตาม
ตองการหรอไม
3. การลงรหสโปรแกรม
4. การทดสอบและตรวจสอบโปรแกรม
1.2 ขอมลทรบเขา(Input) เปนการรบขอมลเขามาทาการ
ประมวลผล ตองคดแยกวาขอมลสวนใดเปนขอมลนาเขา 4. การทดสอบและตรวจสอบโปรแกรม
5. การจดทาคมอเอกสารในการใชโปรแกรม
หรอขอมลนาออก
1.3 การประมวลผม(Process) คอ การนาขอมลทรบเขามา ( )
มาทาการประมวลผลใหไดผลลพธตามทตองการ
1.4 ตวแปล(Variable) เปนตวสาหรบเกนคาขอมลเพอใช( )
ในการอางองในการประมวลผลและแสดงผมขอมล
![Page 2: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/2.jpg)
การกาหนดแผนผงในการแกปญหาการกาหนดแผนผงในการแกปญหา2 1 การเขยนผงงาน เปนการลาดบขนตอนใน 2 1 1 การเขยนผงงานตามลาดบ(Sequential)2.1 การเขยนผงงาน เปนการลาดบขนตอนใน
การเขยนโปรแกรม เรมตงแตกระบวนการ
ทางานแรกจนถงกระบวนการสนสดของงาน ซง
2.1.1 การเขยนผงงานตามลาดบ(Sequential)
เรมตนทางานแรกจนถงกระบวนการสนสดของงาน ซง
การเขยนผงงานมรปแบบการเขยนผงงานแบง
ออกเปน 3 รปแบบ
เรมตน
ออกเปน 3 รปแบบ อานขอมล
ประมวลผล
แสดงผลขอมล
จบการทางาน
![Page 3: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/3.jpg)
2.1.2 การเขยนผงงานแบบมเงอนไข
(Condition)
2.1.3 การเขยนผงงานแบบวนรอบในการทางาน(Loop)
เรมตน เรมตน
อานขอมล อานขอมล
ตรวจสอบ ประมวลผล
ประมวลผล ประมวลผล แสดงผลประมวลผล ประมวลผล
แสดงผล แสดงผล เพมตวนบ
ตรวจสอบ
จบการทางาน จบการทางาน
![Page 4: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/4.jpg)
สญลกษณของผงงาน (Flowchart Symbol) 1. การเรมตน/สนสดการทางาน 6. ตวเชอมตอ
2. กระบวนการ 7. ทศทางการทางาน2. กระบวนการ 7. ทศทางการทางาน
3. การตดสนใจ 8. ทางจอภาพ
4. การอาน/การเขยน
5 การพมพ5. การพมพ
![Page 5: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/5.jpg)
2.2การเขยนคาสงเทยม(PSUEDO CODE)CODE)
2 2 3 การเขยนแบบวนรอบในการทางาน (Loop) 2.2.1 การเขยนคาสงตามลาดบ (Sequential)
Read Num1, Num24O t t N
2.2.3 การเขยนแบบวนรอบในการทางาน (Loop)
If I have moer value than or equal 10 goto ExitRead Num1, Num24Output_Num =
Num1+Num2Write Output Num
Read Num1, Num24Output_Num = Num1+Num2Write Output NumWrite Output_Num
2.2.2 การเขยนคาสงแบบมเงอนไข(Condition)
p _Increment I
Exit( )Read Num1, Num24
If Num> Num22Num= Num1+Num2
Write NumElseElse
Num = Num1-Num2Write Num
![Page 6: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/6.jpg)
3. การลงรหสโปรแกรมหลงจากใชผงงานหรอคาสงเทยม ในการกาหนด
5. การจดทาคมอเอกสารการใชโปรแกรม
โป ไ สหลงจากใชผงงานหรอคาสงเทยม ในการกาหนดแผนในการแกปญหาแลว ขนตอนตอไปเปนการลงรหสโปรแกรม โดยใชภาษาทตองการลงรหส
เมอโปรแกรมไดผานกระบวนการทดสอบและ
ตรวจสอบเรยบรอยแลว ขนตอนตอไปเปนการจดทา
ส ป ใ โป ส เชน ภาษา Pascal, ภาษา C, ภาษา Cobol เปนตน
คมอและเอกสารประกอบการใชโปรแกรม สาหรบ
ทางานตอไป
4. การทดสอบและตรวจโปรแกรม โป เมอโปรแกรมเขยนเสรจเรยบรอยแลว ขนตอน
ตอไปเปนการนาโปรแกรม มาทาการทดสอบและตรวจสอบวาโปรแกรมททาขน สามารถทางานตรวจสอบวาโปรแกรมททาขน สามารถทางานตามทตองการหรอไมโดยนามาทดสอบกบระบบงานจรง ถาตรวจพบขอผดพลาด จะไดระบบงานจรง ถาตรวจพบขอผดพลาด จะไดดาเนนการแกไขใหถกตองตอไป
![Page 7: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/7.jpg)
โปรแกรม Stock สนคารานหนงสอโปรแกรม Stock สนคารานหนงสอโจทย : จงเขยนโปรแกรม Stock รานหนงสอ ซงมขอมลดงน รหสสนคาหนงสอ ซอหนงสอ ผแตงหนงสอ ราคาหนงสอ บวกภาษมลคาเพม
(Vat) และแสดงขอมลออกทางจอภาพ
การวเคราะหงาน
1. ผลลพธ (Output) รหสสนคาหนงสอ ชอหนงสอ ผแตงหนงสอ และราคา
2 ขอมลทรบเขา (Input) รหสสนคาหนงสอ ชอหนงสอ ผแตงหนงสอ และราคาหนงสอ2. ขอมลทรบเขา (Input) รหสสนคาหนงสอ ชอหนงสอ ผแตงหนงสอ และราคาหนงสอ
3. การประมวลผล (Process)
ภาษ = ราคาหนงสอ คณ ภาษมลคาเพมภาษ ราคาหนงสอ คณ ภาษมลคาเพม
ราคา= ราคาหนงสอ บวก ภาษ
4 ตวแปร (Variable)4.ตวแปร (Variable)
รหสสนคา =code ชอหนงสอ =titleผแตงหนงสอ =author ราคา =priceผแตงหนงสอ author ราคา priceราคาหนงสอ =price_Book ภาษ =taxภาษมลคาเพม =vat ภาษมลคาเพม vat
![Page 8: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/8.jpg)
การเขยนผงงาน(Flowchart)
เรมตน
d( d l )Read(code,title…)
Tax = Price_Book x vat
Price = Price_Book + tax
C d Ti l A h iCode, Title, Author, price
จบการทางาน
![Page 9: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/9.jpg)
โปรแกรมโปรแกรม
#include <stdio.h>#include <conio.h> printf(“code %s\n”, code);main(){
h d [5] titl [15] th [25]
Printf(“title %s\n”, title);Printf(“author %s\n” author);
char code[5],title[15],author[25]float price,price_book,tax,vat;clrscr();
Printf(price %2f\n”,price);getch();
clrscr();vat :=0.07;printf(“enter code\n”)scanf(“%s”,&code);p ( \ ) ( , );printf(“enter title\n”)scanf(“%s”,&title);printf(“enter
h \ ”) f(“% ” & h )author\n”)scanf(“%s”,&author);printf(“enter price\n”)scanf(“%s” &price book);price\n )scanf( %s ,&price_book);tax := price_book * vat;price := price book + tax;price : price_book + tax;
![Page 10: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/10.jpg)
ผลลพธ (Output)
enter code 001enter title C Ianguageenter anthor Mr.Kittisak Suleewomenter price 500code 001code 001title C languageauthor Mr Kittisak Suleewomauthor Mr.Kittisak Suleewomprice 535
![Page 11: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/11.jpg)
โปรแกรมหาคาสงสด
โจทย : จงเขยนโปรแกรมเพอหาจานวนเลขคาสงสด ในการรบจานวนตวเลขผานทางแปนพมพ (Keyboard)
การวเคราะหงาน
1. ผลลพธ (Output) จานวนเลขคาสงสด2. ขอมลทรบเขา (Input) จานวนตวเลข3. การประมวลผล (Process)( )
1. จานวนเลขคาสงสด
2 รบจานวนตวเลข2. รบจานวนตวเลข
3. ตรวจสอบเงอนไข
ส ส ใ ส ส ถา ตานวนตวเลข มากกวา จานวนคาสงสด ใหจานวนตวเลขคาสงสด เทากบ จานวน
ตวเลข
4. ถาไมใช ใหไปขอท 2
4.ตวแปร (Variable)
max_number , num
![Page 12: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/12.jpg)
การเขยนผงงาน (Flowchart)เรมตนเรมตน
max = 100max 100
Read (num)
num > max max = num
Not greater than max
i = i+1
i <= 3
จบการทางาน
![Page 13: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/13.jpg)
โปรแกรมโปรแกรม#include <stdio.h> else#include <conio.h>main ( )
printf(yNot greater than \n{);getch();
{
int I,max,num;l ()
}
Clrscr();max = 100;f (i 1 i 3 i )for (i=1 ; i<=3 ; i++){
printf(yEnter number \n{) scanf (y%d{ &num)printf(yEnter number \n{); scanf (y%d{, &num);if (num > max)max = num;max = num;printf(ymax_num %d \n{, max);
![Page 14: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/14.jpg)
ผลลพธ (Output)( p )
benter number 150max 150
![Page 15: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/15.jpg)
โปรแกรมการหาคารากทสอง (Square Root)
โจทย : จงเขยนโปรแกรมหาคารากทสอง(Square root) ในการเรยกใชฟงกชน (Function)
calculate() เพอสคาพารามเตอร(parameter) ไปหาคารากทสอง แลวแสดงคาออกทางจอภาพcalculate() เพอสคาพารามเตอร(parameter) ไปหาคารากทสอง แลวแสดงคาออกทางจอภาพ
การวเคราะหงาน1. ผลลพธ (Output) คารากทสอง2. ขอมลทรบเขา (Input) จานวนตวเลข3. การประมวลผล(Process)
คารากทสอง = spr (จานวนตวเลขX4. ตวแปร (Variable)
คารากทสอง = valueจานวนตวเลข = number
![Page 16: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/16.jpg)
การเขยนผงงาน (Flowchart)
เรมตน
Read (number)
value = sqrt (number)q ( )
valuevalue
จบการทางาน
![Page 17: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/17.jpg)
โปรแกรมโปรแกรม
#include <stdio.h> Int qrt(int s2)#include <conio.h>#include <math.h>I (i )
{
return sqrt(s2);()Int qrt(int);
main ( ){
}ประกาศฟงกชน qtr()
{
int number,sum;clrscr();clrscr();printf(yEnter number \n{); scanf(y%d{, &number);&number);sum = qrt(number);printf(yvalue %d\n{ sum);
เรยกใชฟงกชน qrt()printf(yvalue %d\n{, sum);getch();}}
![Page 18: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/18.jpg)
ผลลพธ (Output)
Enter number 100Enter number 100Value 10
![Page 19: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/19.jpg)
โปรแกรมหายอดขายของพนกงาน
โจทย : จงเขยนโปรแกรมเพอหายอดขายของพนกงานแตละคนในรอบ 12 เดอน และแสดงผลออกทางจอภาพ
การวเคราะหงาน
1.ผลลพธ (Output) ยอดขายของพนกงาน 2.ขอมลทรบเขา (Input) ชอพนงงานและยอดขายแตละเดอน
3.การประมวลผล(Process)1.อานชอพนกงานและยอดแตละเดอนขาย
2.ยอดขายของพนกงาน=ยอดขายของพนกงาน+ ยอดขายแตละเดอน 2.ยอดขายของพนกงาน ยอดขายของพนกงาน ยอดขายแตละเดอน 3.แสดงชอพนกงานและยอดขายของพนกงาน
4 ถาอานชอพนกงานไมครบใหกลบไปท 14.ถาอานชอพนกงานไมครบใหกลบไปท 1
4.ตวแปร(Variable)
lชอพนกงาน = name ยอดขายแตละเดอน = saleยอดขายของพนกงาน = sum
![Page 20: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/20.jpg)
การเขยนผงงาน (Flowchart)
เรมตน
i=i+1 ,j=1จบการทางาน
อานชอพนกงาน
จบการทางาน
อานยอดขายแตละเดอน i>= 100
หาคารวมยยอดขายของพนกงานi=i+1
j=j+1
แสดงชอพนกงาน
ยอดขายพนกงานJ>=12
ยอดขายพนกงาน
![Page 21: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/21.jpg)
โปรแกรม
#i l d di h
โปรแกรม
#include <stdio.h>#include <conio.h>main ( ){
for (j=1 ; j>=12 ; j++){
printf(yEnter sales \n{); scanf(y%d{ &sale);{
char name[15];int I,j,sum,sale;clrscr();
printf(yEnter sales \n{); scanf(y%d{, &sale);sum = sum + sale;}
clrscr();for (i=1 ; i >=100 ; i++){
sum = 0;
printf(yName %s{, name);printf(ySum %d \n{, sum);}sum = 0;
printf(yEnter Name \n{); scanf(y%s{, &name);
}
getch();}
![Page 22: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/22.jpg)
ผลลพธ (Output)ผลลพธ (Output)
Enter name Mr.SurachaiEnter sales 1000Enter sales 1000Enter sales 2000Enter name Miss SomjaiEnter name Miss.SomjaiEnter sales 1500E l 1200Enter sales 1200Name Mr.SurachaiSum 3000Name Miss.SomchaiSum 2700
![Page 23: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/23.jpg)
โปรแกรมอารย(Array) ขนาด 1 มต
โจทย : จงเขยนโปรแกรมแบบอารเรย เกยวกบคาใชจายประจาเดอน ขนาด 1 มต ขอมลประกอบดงนชอเจาของบาน คานา คาไฟ คาเชาบาน และแสดงผลออกทางจอภาพ ชอเจาของบาน คานา คาไฟ คาเชาบาน และแสดงผลออกทางจอภาพ
การวเคราะหงาน
1. ผลลพธ (Output)2. ขอมลทรบ (Input) ( p )3. การประมวล (Process)
1 อานชอเจาของบาน คานา คาไฟ คาเชาบาน 1. อานชอเจาของบาน คานา คาไฟ คาเชาบาน
2. คาใชจายประจาเดอน = คานา+คาไฟ+คาเชาบาน3 ไ ใ ไป 13. ถาอานชอเจาของบานไมครบ ใหกลบไปขอท1
4. แสดงชอเจาของบาน คาใชจายประดาเดอน
4. ตวแปร(Varible)ชอเจาของบาน = name คานา = water คาไฟ = weterคาเชาบาน = rent คาใชจายประจาเดอน = expend
![Page 24: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/24.jpg)
การเขยนผงงาน (Flowchart)เรมตน
i = l
อานชอเจาของบาน....
หาคาใชจายประจาเดอนจบการทางาน
i > 100
j=j+ l
i > 100 i >=100
i >=100
แสดงชอเจาของบานและ
คาใชจายประจาเดอนi = i+1
![Page 25: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/25.jpg)
โปรแกรม
#include <stdio.h>#include <conio.h>
for (i=1 ; i >=100 ; i++){
main ( ){
h [15]
{
printf(yname %s \n{, name[i]);printf(ywater %d \n{, water[i]);
char name[15];int i,water[100],elec[100],rent[100],sum[100];clrscr();
printf(yelectric %d \n{, elec[i]);printf(yrent %d \n{, rent[i]);printf(ysum %d \n{ sum[i]);();
for (i=1 ; i >=100 ; i++){
i tf( E t \ {) f( % { & [i])
printf(ysum %d \n{, sum[i]);}
getch();printf(yEnter name \n{); scanf(y%s{, &name[i]);printf(yEnter water \n{); scanf(y%d{, &water[i]);printf(yEnter electric \n{); scanf(y%d{, &elec[i]);
}
p (y \ {); (y {, [ ]);printf(yEnter rent \n{); scanf(y%d{, &rent[i]);sum[i] = water[i] + elec[i] + rent[i];}}
![Page 26: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/26.jpg)
ผลลพธ (Output)ผลลพธ (Output)Enter name MrWanchai name MissWandeeEnter name Mr.WanchaiEnter water 120Enter electric 150
name Miss.Wandeewater 200electric 100Enter electric 150
Enter rent 1500Enter name MissWandee
electric 100rent 1500sum 1800Enter name Miss.Wandee
Enter water 200Enter electric 100
sum 1800
Enter electric 100Enter rent 1500name MrWanchainame Mr.Wanchaiwater 120electric 150electric 150rent 1500Sum 1770Sum 1770
![Page 27: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/27.jpg)
โปรแกรมอารเรย(Array)ขนาด 2 มต
โจทย : จงเขยนโปรแกรมแบบอารเรย เพอหาคะแนนทดสอบ แบบอารเรยขนาด 2 มต ขอมลประกอบดวยชอนกศกษา คะแนนทดสอบจานวน 3 ครง แลวแสดงผลออกทางจอภาพขอมลประกอบดวยชอนกศกษา คะแนนทดสอบจานวน 3 ครง แลวแสดงผลออกทางจอภาพ
การวเคราะหงาน
1.ผลลพธ (Output) คะแนนทดสอบรวม2.ขอมลทรบเขา (Input) ชอนกศกษา คะแนนทดสอบ 3 ครง ( p )3.การประมวลผล(Process)
1 1 อานชอนกศกษา และคะแนนทดสอบ 3 ครง1.1.อานชอนกศกษา และคะแนนทดสอบ 3 ครง
1.2.คะแนนทดสอบรวม = คะแนนทดสอบรวม + คะแนนทดสอบ 3 ครง1 3 ช ศ ไ ใ ไป 11.3.ถาอานชอนกศกษาไมครบ ใหกลบไปทขอท1
1.4.แสดงชอนกศกษา คะแนนทดสอบรวม
ตวแปร (Variable)ชอนกศกษา = name คะแนนทดอบ 3ครง = score คะแนนสอบรวม = sum
![Page 28: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/28.jpg)
การเขยนผงงาน (Flowchart)
เรมตน
i=i , j=1
อานชอนกศกษา
อานคะแนน3ครง
หาคะแนนทดสอบรวมหาคะแนนทดสอบรวม
j = j+1 i 100j = j+1 i >=100ตอหนา
ถดไปi = i+1 j >=3
ถดไป
![Page 29: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/29.jpg)
การเขยนผงงาน (Flowchart)ตอจาก
หนาแรกหนาแรก
j = j+1
แสดงชอนกศกษา
แสดงคะแนนทดสอบ
และคะแนนทดสอบรวม
i >=100
และคะแนนทดสอบรวม
j = j+1 จบการทางาน i > 100
j > 3
j j+1
i i+1
จบการทางาน
j >=3 i = i+1
![Page 30: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/30.jpg)
โปรแกรม#include <stdio.h>#include <conio.h>
}
}main ( ){
for ( i=1 ; i<=100 ; i++ );{
int i, j, score[100][3], sum[3];char name[50];
printf(yName %s\n{, name[i]);for ( j=1 ; j<=3 ; j++);[ ];
clrscr();for ( i=1 ; i<=100 ; i++ );
( j ; j ; j );{
printf(yScore %d\n{, score[i][j];( ; ; );{
printf(yEnter name\n{); scanf(ys{, &name[i]);
p (y \ {, [ ][j];}
printf(ySum %d \n{, sum[i]);p (y \ {); (y {, [ ]);sum[i]=0;for ( j=1 ; j<=3 ; j++);
p (y \ {, [ ]);}
getch();( j ; j ; j );{
printf(yEnter score \n{); scanf(y%d{, &score[i][j]);
g ();}
p (y \ {); (y {, [ ][j]);sum[i] = sum[i] + score[i][j];
![Page 31: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/31.jpg)
ผลลพธ(Output)ผลลพธ(Output)Enter name Miss AruneeEnter score 70Enter score 80Enter name Mr. PomchaiEnter score 90Enter score 60Name Miss AruneeScore 70Score 80Sume 150Name Mr.PomchaiScore 90Score 60Sume 150
![Page 32: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/32.jpg)
โปรแกรมหาคาเลขยกกาลง (Exponential)โจทย : จงเขยนโปรแกรมหาคาเลขยกกาลงโดยแบงฟงกชน(Function) ออกเปน 3ฟงกชน
(Function) ไดแก (Function) ไดแก
ฟงกชน itile() ใชแสดงหวขอความ (Text)ฟงกชน exp() ใชแสดงการรบขอมลฟงกชน exp() ใชแสดงการรบขอมล
ฟงกชน cal() ใชในการหาคาเลขยกกาลง (Exponential) และแสดงผลออกทางจอภาพการวเคราะหงาน
1.ผลลพธ (Output) คาเลขยกกาลง 2.ขอมลทรบเขา (Input) ตวเลขจานวนเตม 3.การประมวลผล(Process)( )
1.อานตวเลข2 หาคาเลขยกกาลง2.หาคาเลขยกกาลง
3.แสดงคาเลขยกกาลง
ป (V i bl )4. ตวแปร(Variable)คาเลขยกกกาลง = exponential
![Page 33: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/33.jpg)
การเขยนผงงาน(Flowchart)
เรมตนเรมตน
อานตวเลข
หาคาเลขยกกาลง
แสดงคาเลขยกกาลง
จบการทางาน
![Page 34: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/34.jpg)
โปรแกรม#include <stdio.h>#include <conio.h>
void exp(){
#include <math.h>main ( )
int number=0;float exponential;( )
{
clrscr();
pprintf(yEnter value exponential \n{);scanf(y%d{, &number);()
title();exp();
(y { )exponential = cal(number);printf(yValue %.2f \n{, exponential);p()
return 0;}
p (y { p )getch();}
เรยกใชฟงกชนcal()เพอสงคาพารามเตอร(parameter)
void title(){
float cal(int a){
พารามเตอร(parameter)
clrscr();printf(y Calculate Exponential \n{);
return exp(n);}
สงคาเลขยกกาลง(Exponential)กลบไปยงฟงกชนทเรยกp (y p {)
}กลบไปยงฟงกชนทเรยก
![Page 35: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/35.jpg)
(O t t)ผลลพธ (Output)
Calculate ExponentialpEnter value exponential 10Value 22026.47
![Page 36: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/36.jpg)
โปรแกรมประวตพนกงานโจทย : จงเขยนโปรแกรมประวตของพนกงานเพอไหโบนส(Bonus) ประจาป ประกอบดวย ชอพนกงาน
ตาแหนงพนกงาน และเงนเดอน โดยเขยนเปนฟงกชน(Function) ประกอบดวย ตาแหนงพนกงาน และเงนเดอน โดยเขยนเปนฟงกชน(Function) ประกอบดวย
1. ฟงกชน entry() ในการรบขอมล2 ฟงกชน display() ในการแสดงผล2. ฟงกชน display() ในการแสดงผล
การวเคราะหงาน
(O t t) โ 1. ผลลพธ (Output) ชอพนกงาน ตาแหนงงาน เงนเดอน และโบนส
2. ขอมลทรบเขา (Input) ชอพนกงาน ตาแหนงงาน และเงนเดอน
3. การประมวลผล(Process)1. อานชอพนกงาน ตาแหนงงาน และเงนเดอน โบนส = คด10% ของเงนเดอน2. ถาเงนดอนอยระหวาง 10,000 ถง 15,000 บาท โบนส = คด15% ของเงนเดอน3 ถาเงนเดอนมากกวา 20,000 บาท โบนส = คด20% ของเงนเดอน3. ถาเงนเดอนมากกวา 20,000 บาท โบนส คด20% ของเงนเดอน
4. ตวแปร (Variable)ชอพนกงาน = name ตาแหนงงาน = positionชอพนกงาน = name ตาแหนงงาน = positionเงนเดอน = salary โบนส = bonus
![Page 37: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/37.jpg)
การเขยนผงงาน(Flowchart)เรมตน
อานตวเลอกเมน
เงอนไขเลอก (1) Display เลอก (2) Display
อานขอมล ส อานขอมล แสดงคาเลขยกกาลง
ตอหนา
ถดไปreturn
ถดไป
![Page 38: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/38.jpg)
การเขยนผงงาน(Flowchart)ตอจาก
หนาแรก
10000 ‐ 1500
คดโบนส 10%
1500 ‐ 2000
คดโบนส 15%
>20000
คดโบนส 15%
คดโบนส 20%โปรแกรม
![Page 39: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/39.jpg)
โปรแกรม#include <stdio.h>#include <conio.h>
ch = getche();switch(ch) {
void entry (void);void display (void);
( ) {case 1 : entry();break;p y ( );
char ch, name[15], position [15];int bonus, salary, sum;
;case 1 : display();break;, y, ;
main ( ){
;default: printf(yError \n{);}
clrscr();do {
}while (ch != 0 );}{
printf(yM a i n M e n u \n{);printf(y0] Retrun to system \n{);
void entry(){p (y ] y \ {);
printf(y1] Entry data \n{);printf(y2] Display data \n{);
clrscr();printf(yEnter name \n{); scanf(y%s{, p (y ] p y \ {);
printf(y Select choice \n{);p (y \ {); (y {,&name);
![Page 40: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/40.jpg)
โปรแกรมprintf(yEnter position{); scanf(y%s{, &position);
else{&position);
printf(yEnter salary \n{); scanf(y%d{, &salary);
{
if (salary > 20001){&salary);
if (salary > 10000 && salary < 15000){
{
bonus = salary * 20/100;sum = salary + bonus;{
bonus = salary * 10/100;sum = salary + bonus;
sum salary + bonus;}
}sum salary + bonus;}
else
}
getch();}else
if (salary > 15001 && salary < 20000){
}
void display(){{
bonus = salary * 15/100;sum = salary + bonus;
{
clrscr();printf(yName %s \n{, name);sum salary + bonus;
}
printf(yName %s \n{, name);
![Page 41: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/41.jpg)
โปรแกรมโปรแกรม
printf(yPosition %s \n{, position);printf(ySalary %d \n{ salary);printf(ySalary %d \n{, salary);printf(yNet_Salary %.2f \n{,sum);getch();getch();}
![Page 42: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/42.jpg)
ผลลพธ(Output)ผลลพธ(Output)
M i M N Mi P t h lM a i n M e n u0] Return to system1] E t d t
Name Miss. PatchaleePosition ProgrammerS l 120001] Entry data
2] Display dataS l t h i
Salary 12000Net_Salary 13200
Select choiceเลอก 1 ไปท Entry data 1 ไป Display dataเลอก 1 ไปท Display data
ไมเลอก 1 และ 2 ปรากฏขอความวา ErrorE t Mi P t h lEnter name Miss. PatchaleeEnter position ProgrammerEnter salary 12000Enter salary 12000
![Page 43: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/43.jpg)
โปรแกรม stock สนคาโ : โป โ ส (Record) ส ป ส ส โจทย : จงเขยนโปรแกรมโครงสราง(Record) เพอชอสนคา ประกอบดวย ชอสนคา จานวนสนคา ราคาสนคา และแสดงผลออกทางจอภาพ
การวเคราะหงาน
1. ผลลพธ (Output) ชอสนคา จานวนสนคา และราคาสนคา( p ) 2. ขอมลทรบเขา (Input) ชอสนคา จานวนสนคา และราคาสนคา 3. การประมวลผล(Process)( )
1. อานชอสนคา จานวนสนคา ราคาสนคา
2. แสดงชอสนคา จานวนสนคา ราคาสนคา
3. ถาอานชอสนคาไมครบ ใหดกลบไปขอ 1
4. ตวแปร(Variable)( )ชอสนคา = product_name จานวนสนคา = unitราคาสนคา = pricep
![Page 44: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/44.jpg)
การเขยนผงงาน(Flowchart)เรมตน
I = 1
อานชอสนคา
แสดงผล
I = i+1
I >= 10 จบการทางานI >= 10 จบการทางาน
![Page 45: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/45.jpg)
โปรแกรมโปรแกรม#include <stdio.h>#i l d i h
printf(yEnter price \n{); #include <conio.h>{
d {
p (y p \ {);scanf(y%f{, &price);printf(yProduct name %s \n{,
stuct product {char name[15];i i i
p (y _ \ {,pro.name);printf(yUnit %d \n{, pro.unit);
int unit, price;}; stuct product pro;i i
p (y \ {, p );printf(yPrice %f \n{, price);}
int i;clrscr();f ( i 1 i 10 i )
getch();}
for ( i=1 ; i<=10 ; i++){
i f( E P d \ {)printf(yEnter Product_name \n{);scanf(y%s{, &pro_name):i tf( E t it \ {) f( %d{ & it)printf(yEnter unit \n{); scanf(y%d{, &pro.unit);
![Page 46: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/46.jpg)
ผลลพธ(Output)ผลลพธ(Output)
Enter product_name TelevisionEnter unit 1Enter price 9000Product name Television_Unit 1Price 9000
![Page 47: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/47.jpg)
โปรแกรมแสดงคาทอย (Address)ของขอมลโจทย : จงเขยนโปรแกรมเพอแสดงคาทอย(Address)ของขอมล
การวเคราะหงาน
1 ผลลพธ (Output) แสดงคาทอย (Address)1. ผลลพธ (Output) แสดงคาทอย (Address) 2. ขอมลทรบเขา (Input) จานวนตวเลข 3 การประมวลผล(Process) 3. การประมวลผล(Process)
1. อานจานวนตวเลข
2 ตวแปรพอยนเตอร(Pointre) ชไปท จานวนตวเลข2. ตวแปรพอยนเตอร(Pointre) ชไปท จานวนตวเลข
3. แสดงคาทอย (Address)4 ตวแปร (Variable)4. ตวแปร (Variable)
จานวนตวเลข = numberพอยนเตอร = ptrพอยนเตอร ptr
![Page 48: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/48.jpg)
การเขยนผงงาน(Flowchart)
เรมตน
อานตวเลข
กาหนดคาพอยนเตอร
แสดงคาทอย,ขอมล
จบการทางานจบการทางาน
![Page 49: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/49.jpg)
โปรแกรมโปรแกรม
#include <stdio.h>#include <conio.h>{
int *ptr;int number;;clrscr();printf(yEnter Number \n{); scanf(y%d{, &number);p (y \ {); (y {, );ptr = &number;printf(yAddress %p\n{, &ptr);p (y p\ {, p );printf(yData %d \n{, *ptr);getch();g ();}
![Page 50: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/50.jpg)
ผลลพธ(Output)ผลลพธ(Output)
Enter Number 100Address FFF4Data 100
![Page 51: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/51.jpg)
โปรแกรมสลบคา (Swap)โจทย : จงเขยนโปรแกรมเพอสลบคา(Swap) ระหวางคา A=100 B=200 แลวแสดงคาออกทางจอภาพ
การวเคราะหงาน
( )1. ผลลพธ (Output) คา A และคา B 2. ขอมลทรบเขา (Input) คา A และคา B
( ) 3. การประมวลผล(Process)temp = AA = BB = Temp( bl )4. ตวแปร (Varisble)A, B, Temp
![Page 52: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/52.jpg)
การเขยนผงงาน(Flowchart)เรมตน
A = 1000B = 2000B = 2000
Temp = AA = B
B= temp
Print A,B
จบการทางาน
![Page 53: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/53.jpg)
โปรแกรมโปรแกรม#include <stdio.h>#include <conio.h>{
clrscr();int A, B, Temp;A = 1000;B = 2000;Temp = A;A = B;B = Temp;printf(y Value A %d \n{, A);printf(y Value B %d \n{, B);getch();}
![Page 54: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/54.jpg)
ผลลพธ(Output)ผลลพธ(Output)
Value A 2000Value B 1000Value B 1000
![Page 55: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/55.jpg)
โปรแกรมจดเรยงขอมล(Sort Data) ( )โจทย : จงเขยนโปรแกรมเพอจดเรยงขอมล(Sort Data)แบบ Buble Sort แลวแสดงผลออกทางจอภาพ
การวเคราะหงาน
1 ผลลพธ(Output)จานวนตวเลขทจดเรยง1.ผลลพธ(Output)จานวนตวเลขทจดเรยง2.ขอมลทรบเขา(input)ขอมลแบบอารเรย(Array)
ป (P )3.การประมวลผล(Process)1.จบตวเลขขนมา 1 ค
2.นามาเปรยบเทยบดวาคาตวเลขไหนมากกวา
3.ถาเลขบนมากกวาเลขลางใหสลบทไปเรอยๆ
4.ตวแปร(Variable)temp=เกบคาชวคราวp
number=ตวเลข
![Page 56: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/56.jpg)
การเขยนผงงาน(Flowchart)เรมตน
Number [5] = {7,4, 3,2,8}
if number[i]>number[i+l]Temp =number[i]
Number[i]=number[i+l]Number[i] number[i l]Number[i+l]=temp
Display number[i]
จบการทางาน
![Page 57: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/57.jpg)
โปรแกรม#include <stdio.h>#include <conio.h>
printf(yData Sorted \n{);for ( i=1 ; i<=max ; i++ )#include <conio.h>
{
int i, temp, max=5, number[5] =
for ( i 1 ; i< max ; i++ ){
printf(y%d {, number[i]);int i, temp, max 5, number[5] {7,4,3,2,8};clrscr();
printf(y%d {, number[i]);}
getch();clrscr();for ( i=1 : i<=max ; i++ ){
getch();}
{
if ( number[i] > number[i+1] ){{
temp = number[i];number[i] = number[i+1];number[i] number[i+1];number[i+1] = temp;}}
}
![Page 58: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/58.jpg)
ผลลพธ(Output)ผลลพธ(Output)
Data Sorted2 3 4 7 82 3 4 7 8
![Page 59: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/59.jpg)
โปรแกรมสตรคณโปรแกรมสตรคณ
โจทย : จงเขยนโปรแกรมสตรแลวแสดงผลออกทางจอภาพ
(V i bl )การวเคราะหงาน 4.ตวแปร (Variable)1.ผลลพธ (Output) สตรคณ number = แมสตรคณ
(Input) ใ 2.ขอมลทรบเขา (Input) ใสแมสตรคณทตองการ3.การประมวลผล (Process)
รบแมสตรคณรบแมสตรคณfor (i=แมสตรคณ ; i<=12 ; i++) (แถว){{
for (j=1 ; j<=12 ; j++) (คอลมน){{printf(“%dx.%d = %d\n” , I,j,i*j);}
}}
![Page 60: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/60.jpg)
การเขยนผงงาน(Flowchart) เรมตน
Read(number)
i = number, j = 1จบการทางาน
i x jจบการทางาน
j = j+1i <= 12
j <= 12 i i+1j <= 12 i = i+1
![Page 61: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/61.jpg)
โปรแกรม#include <stdio.h>#include <conio h>#include <conio.h>{
int i j number;int i, j, number;printf(yEnter Number\n{); scanf(y%d{, &number);&number);for ( i=number ; i<=12 ; i++ ){{
for ( j=1 ; j<=12 ; j++){{
printf(y%d x %d{, i, j, i*j);}}
}
getch();getch();}
![Page 62: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/62.jpg)
ผลลพธ(Output)ผลลพธ(Output)Enter Number 22 x 1 = 22 x 2 = 42 x 3 = 62 x 4 = 82 x 4 82 x 5 = 102 x 6 = 122 x 6 = 122 x 7 = 142 8 162 x 8 = 162 x 9 = 182 x 10 = 202 x 11 = 222 x 12 = 24
![Page 63: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/63.jpg)
โปรแกรมสม (Random) ตวเลขโจทย : จงเขยนโปรแกรมสมหาคาสงสด แลวแสดงผลออกทางจอภาพ
การวเคราะหงาน
(O ) 4 ตวแปร (Variable)1.ผลลพธ (Output) คาสงสด2.ขอมลทรบเขา (Input) รบตวแปรเปนเลขจานวนเตม
4. ตวแปร (Variable)temp = เกบคาสงสด
2 3 3.การประมวลผล (Process)รบตวแปรเปนเลขจานวนเตม s1, s2 s3
s1, s2, s3 = เลขจานวนเตม,
temp = s1if s2 > tempif s2 > temp
temp = s2if 3 tif s3 > temp
temp = s3
![Page 64: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/64.jpg)
การเขยนผงงาน(Flowchart)เรมตน
d ( )Read (s1, s2, s3)
temp = s1if s2 > tempif s2 > temptemp = s2fif s3 > temptemp = s3
Display tempDisplay temp
จบการทางาน
![Page 65: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/65.jpg)
โปรแกรม#include <stdio.h>#include <conio h>#include <conio.h>{
int temp s1 s2 s3;int temp, s1, s2, s3;clrscr();printf(yEnter number \n{);printf(yEnter number \n{);scanf(y%d{, &s1, &s2, &s3);temp = s1;temp = s1;if s2 > temptemp = s2temp = s2if s3 > temptemp = s3temp = s3printf(y Output Maximum %d \n{, temp);getch();getch();}
![Page 66: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/66.jpg)
ผลลพธ(Output)( p )
Enter number 12, 45, 30Output Maximum 45Output Maximum 45
![Page 67: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/67.jpg)
โปรแกรมแสดงคา ASCII CODEโจทย : จงเขยนโปรแกรมแสดง Ascii Code แลวแสดงผลออกทางจอภาพ
การวเคราะหงานการวเคราะหงาน
1.ผลลพธ (Output) คา ASCII2 (Input) 0 256
4. ตวแปร (Variable)I = แสดงคา ASCLL CODE2.ขอมลทรบเขา (Input) ตวเลข 0 ถง 256
3.การประมวลผล (Process)
I แสดงคา ASCLL CODE
for ( i=0 ; i<=256 ; i++ ){ printf(“ %d = %c \n{, i, i);if i == 80if i 80break
} }
![Page 68: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/68.jpg)
การเขยนผงงาน(Flowchart) เรมตน
i = 1
ASCII CODE
i i+1i = i+1
i <= 256
จบการทางานจบการทางาน
![Page 69: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/69.jpg)
โปรแกรม
#include <stdio.h>#include <conio.h>{
int i;printf(y ASCII CODE TABLE \n{);for ( i=70 ; i<=256 ; i++ ){
printf(y%d = %c \n{, i,i);if i == 80break;}
getch();}
![Page 70: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/70.jpg)
ผลลพธ(Output)ASCII CODE TABLE70 F70 F71 G73 G73 G74 H75 I75 I76 J77 K77 K78 L79 M79 M82 N
![Page 71: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/71.jpg)
โปรแกรมหาคาฟงกชน (Function)
โจทย : จงเขยนโปรแกรมหาคาF(x) = x2 + y2 h 10 / 3 แลวแสดงผลออกทางจอภาพ
การวเคราะหงาน
1.ผลลพธ (Output) คา F(x)2 ขอมลทรบเขา (Input) x2 + y2 h 10 / 32.ขอมลทรบเขา (Input) x2 + y2 h 10 / 33.การประมวลผล (Process)
h /temp = x2 + y2 h 10 / 34. ตวแปร (Variable)
temp = เกบคาฟงกชนx2 = คา x ยกกาลงy2 = คา y ยกกาลง
![Page 72: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/72.jpg)
การเขยนผงงาน(Flowchart)เรมตน
Read (x y)Read (x,y)
temp = x2 + y2 o 10 / 3
Display temp
จบการทางาน
![Page 73: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/73.jpg)
โปรแกรม#i l d tdi h#include <stdio.h>#include <conio.h>{{
int s1, s2, temp;l ()clrscr();printf(yEnter value X \n{); scanf(y%d{, &s1);i tf( E t l Y \ {) f( %d{ & 2)printf(yEnter value Y \n{); scanf(y%d{, &s2);
temp = F(x, y);i tf( V l %2f \ { t )printf(yValue %2f \n{, temp);
getch();}}
float F(int x, int y){{
return ( x * x + y * y h 10 / 3 )}}
![Page 74: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/74.jpg)
ผลลพธ(Output)
Enter value X 3Enter value Y 3Enter value Y 3Value 2.66
![Page 75: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/75.jpg)
โปรแกรมหาพนทวงกลมโจทย : จงเขยนโปรแกรมหาพนทวงกลม¶r2แลวแสดงผลออกทางจอภาพ
การวเคราะหงาน1 ผลลพธ (Output) หาคาพนทวงกลม1.ผลลพธ (Output) หาคาพนทวงกลม2.ขอมลทรบเขา (Input) ¶r2
ป (P )3.การประมวลผล (Process)pi = 3.1428รบรศมวงกลม r2พนทวงกลม = pi x r2p
4. ตวแปร (Variable)pi = คา ¶r2pi = คา ¶r2r = รศมวงกลม
![Page 76: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/76.jpg)
การเขยนผงงาน(Flowchart) เรมตน
Pi = 3.1428
Read (r)
พนทวงกลม = pi x r2
พนทวงกลม
บการทางานจบการทางาน
![Page 77: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/77.jpg)
โปรแกรม#include <stdio.h>#include <conio.h>{
int r;clrscr();printf(yEnter redius \n{); scanf(y%d{, &r);p (y {) (y { )printf(yArea of cycle %.2f \n{, cycle(r) );getch();g ()}
float cycle(int r1)y ( ){
return (pi * r * r )(p )}
![Page 78: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/78.jpg)
ผลลพธ(Output)
Enter radius 5Area of cycle 78 57Area of cycle 78.57
![Page 79: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/79.jpg)
โปรแกรมหาพนทสามเหลยมโปรแกรมหาพนทสามเหลยมโจทย : จงเขยนโปรแกรมพนทสามเหลยม แลวแสดงผลออกทางจอภาพ
การวเคราะหงาน1.ผลลพธ (Output) หาคาพนทสามเหลยม2 ขอมลทรบเขา (Input) ระยะฐาน ระยะสง2.ขอมลทรบเขา (Input) ระยะฐาน ระยะสง
3.การประมวลผล (Process)½ x ระยะฐาน x ระยะสง½ x ระยะฐาน x ระยะสง
4. ตวแปร (Variable)bbase = ระยะฐานheight = ระยะสง
![Page 80: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/80.jpg)
การเขยนผงงาน(Flowchart)
เรมตน
Read (base height)Read (base, height)
1/2 x base x height
พนทสามเหลยม
จบการทางานจบการทางาน
![Page 81: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/81.jpg)
โปรแกรม
#include <stdio.h>#include <conio.h>
float area(int b, int h){
float area(int, int);main ()
return (0.5 * b * h);}()
{
clrscr();()int base, height;printf(yEnter base \n{); scanf(y%d{, p (y {) (y {&base);printf(yEnter height \n{); scanf(y%d{, p (y g {) (y {&height);printf(yArea %.2f \n{, area(base, height) );p (y { ( g ) )getch();return 0;}
![Page 82: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/82.jpg)
ผลลพธ(Output)
Enter base 3Enter height 4Area 6.00
![Page 83: หลักการเข ียนโปรแกรมpws.npru.ac.th/sombat/data/files/หลักการเขียน...2.1.2 การเขียนผังงานแบบม](https://reader033.fdocuments.us/reader033/viewer/2022060223/5f07d64e7e708231d41efffe/html5/thumbnails/83.jpg)