1:   #include <stdio.h> 2:   #include <stdlib.h> 3:   #include <conio.h> 4: 5:   void add() { 6:       int num1, num2, res...
44:       printf("t%d * %d = %dn", num1, num2, result);45:   }46:47:   void divide() {48:       float num1, num2, result;4...
87:              case q:88:                   printf("nnGood bye!!!n");89:           }90:       } while ((c != q));91: }92...
Upcoming SlideShare
Loading in …5
×

ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชัน

900 views
792 views

Published on

ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชั

Published in: Technology, Business
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
900
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
5
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

ตัวอย่างการเขียนโปรแกรม โดยใช้ฟังก์ชัน

  1. 1. 1: #include <stdio.h> 2: #include <stdlib.h> 3: #include <conio.h> 4: 5: void add() { 6: int num1, num2, result; 7: 8: printf("nn"); 9: printf("Input number 1: ");10: scanf("%d", &num1);11: printf("Input number 2: ");12: scanf("%d", &num2);13:14: result = num1 + num2;15:16: printf("t%d + %d = %dn", num1, num2, result);17: }18:19: void subtrack() {20: int num1, num2, result;21:22: printf("nn");23: printf("Input number 1: ");24: scanf("%d", &num1);25: printf("Input number 2: ");26: scanf("%d", &num2);27:28: result = num1 - num2;29:30: printf("t%d - %d = %dn", num1, num2, result);31: }32:33: void multiple() {34: int num1, num2, result;35:36: printf("nn");37: printf("Input number 1: ");38: scanf("%d", &num1);39: printf("Input number 2: ");40: scanf("%d", &num2);41:42: result = num1 * num2;43:
  2. 2. 44: printf("t%d * %d = %dn", num1, num2, result);45: }46:47: void divide() {48: float num1, num2, result;49:50: printf("nn");51: printf("Input number 1: ");52: scanf("%f", &num1);53: printf("Input number 2: ");54: scanf("%f", &num2);55:56: result = num1 / num2;57:58: printf("t%.2f / %.2f = %.2fn", num1, num2, result);59: }60:61: void menu() {62: char c;63:64: do {65: printf("n--- MAIN MENU ---n");66: printf("A) Additionaln");67: printf("S) Subtrackn");68: printf("M) Multiplen");69: printf("D) Dividen");70: printf("Q) Quitn");71: printf(" Select choice: ");72: c = getch();73:74: switch (c) {75: case a:76: add();77: break;78: case s:79: subtrack();80: break;81: case m:82: multiple();83: break;84: case d:85: divide();86: break;
  3. 3. 87: case q:88: printf("nnGood bye!!!n");89: }90: } while ((c != q));91: }92:93: int main() {94: menu();95: system("PAUSE");96: return 0;97: }98:

×