SlideShare a Scribd company logo
1:   #include <stdio.h>
 2:   #include <stdlib.h>
 3:
 4:   int main() {
 5:       int score;
 6:
 7:       printf("Enter score: ");
 8:       scanf("%d", &score);
 9:
10:       if ((score >= 0) && (score <= 100)) {
11:           switch (score / 10) {
12:               case 10:
13:               case 9:
14:                   printf("Grade: A");
15:                   break;
16:               case 8:
17:                   if ((score % 10) >= 5)
18:                        printf("Grade: B+");
19:                   else
20:                        printf("Grade: B");
21:                   break;
22:               case 7:
23:                   if ((score % 10) >= 5)
24:                        printf("Grade: B");
25:                   else
26:                        printf("Grade: C+");
27:                   break;
28:               case 6:
29:                   printf("Grade: C");
30:                   break;
31:               case 5:
32:                   if ((score % 10) >= 5)
33:                        printf("Grade: D+");
34:                   else
35:                        printf("Grade: D");
36:                   break;
37:               default :
38:                   printf("Grade: F");
39:           }
40:       } else
41:           printf("Score over scope");
42:
43:       printf("nn");
44:       system("PAUSE");
45:       return 0;
46:   }
47:

More Related Content

What's hot (6)

Practica
PracticaPractica
Practica
 
Presentación1
Presentación1Presentación1
Presentación1
 
Fibonacci Numbers in Modulo N
Fibonacci Numbers in Modulo NFibonacci Numbers in Modulo N
Fibonacci Numbers in Modulo N
 
Taller
TallerTaller
Taller
 
Sqlcheetsheet
SqlcheetsheetSqlcheetsheet
Sqlcheetsheet
 
Comparison of 2 hotels websites
Comparison of 2 hotels websitesComparison of 2 hotels websites
Comparison of 2 hotels websites
 

Similar to เขียนโปรแกรมภาษา C: คำสั่ง switch

Chap7_b Control Statement Looping (3).pptx
Chap7_b Control Statement Looping (3).pptxChap7_b Control Statement Looping (3).pptx
Chap7_b Control Statement Looping (3).pptx
FakhriyArif
 
C basics
C basicsC basics
C basics
MSc CST
 

Similar to เขียนโปรแกรมภาษา C: คำสั่ง switch (20)

Chapter 5 Balagurusamy Programming ANSI in c
Chapter 5 Balagurusamy Programming ANSI  in cChapter 5 Balagurusamy Programming ANSI  in c
Chapter 5 Balagurusamy Programming ANSI in c
 
Vcs4
Vcs4Vcs4
Vcs4
 
Chap7_b Control Statement Looping (3).pptx
Chap7_b Control Statement Looping (3).pptxChap7_b Control Statement Looping (3).pptx
Chap7_b Control Statement Looping (3).pptx
 
Simple C programs
Simple C programsSimple C programs
Simple C programs
 
C if else
C if elseC if else
C if else
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
 
Cprogramcontrolifelseselection3
Cprogramcontrolifelseselection3Cprogramcontrolifelseselection3
Cprogramcontrolifelseselection3
 
Visula C# Programming Lecture 3
Visula C# Programming Lecture 3Visula C# Programming Lecture 3
Visula C# Programming Lecture 3
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
C basics
C basicsC basics
C basics
 
Technical questions for interview c programming
Technical questions for interview  c programmingTechnical questions for interview  c programming
Technical questions for interview c programming
 
C tech questions
C tech questionsC tech questions
C tech questions
 
C programms
C programmsC programms
C programms
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]
 
C
CC
C
 
BCSL 058 solved assignment
BCSL 058 solved assignmentBCSL 058 solved assignment
BCSL 058 solved assignment
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 

More from Warawut

Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7
Warawut
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6
Warawut
 

More from Warawut (20)

Database design
Database designDatabase design
Database design
 
Business Computer Project 4
Business Computer Project 4Business Computer Project 4
Business Computer Project 4
 
Object-Oriented Programming 10
Object-Oriented Programming 10Object-Oriented Programming 10
Object-Oriented Programming 10
 
Object-Oriented Programming 9
Object-Oriented Programming 9Object-Oriented Programming 9
Object-Oriented Programming 9
 
Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8
 
Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5
 
Management Information System 4
Management Information System 4Management Information System 4
Management Information System 4
 
Object-Oriented Programming 5
Object-Oriented Programming 5Object-Oriented Programming 5
Object-Oriented Programming 5
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3
 
Management Information System 3
Management Information System 3Management Information System 3
Management Information System 3
 
Business Computer Project 2
Business Computer Project 2Business Computer Project 2
Business Computer Project 2
 
Chapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemChapter 2 Strategy & Information System
Chapter 2 Strategy & Information System
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MIS
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 

Recently uploaded (20)

The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 

เขียนโปรแกรมภาษา C: คำสั่ง switch

  • 1. 1: #include <stdio.h> 2: #include <stdlib.h> 3: 4: int main() { 5: int score; 6: 7: printf("Enter score: "); 8: scanf("%d", &score); 9: 10: if ((score >= 0) && (score <= 100)) { 11: switch (score / 10) { 12: case 10: 13: case 9: 14: printf("Grade: A"); 15: break; 16: case 8: 17: if ((score % 10) >= 5) 18: printf("Grade: B+"); 19: else 20: printf("Grade: B"); 21: break; 22: case 7: 23: if ((score % 10) >= 5) 24: printf("Grade: B"); 25: else 26: printf("Grade: C+"); 27: break; 28: case 6: 29: printf("Grade: C"); 30: break; 31: case 5: 32: if ((score % 10) >= 5) 33: printf("Grade: D+"); 34: else 35: printf("Grade: D"); 36: break; 37: default : 38: printf("Grade: F"); 39: } 40: } else 41: printf("Score over scope"); 42: 43: printf("nn"); 44: system("PAUSE"); 45: return 0; 46: } 47: