KuoHsiangYu

testArithmetic_1

Nov 18th, 2020
689
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. void A(int n3) {
  4.     printf("答案是:");
  5.     printf("%d\n", n3);
  6. }
  7.  
  8. int main(int argc, char *argv[]) {
  9.     int n1 = 0;
  10.     int n2 = 0;
  11.     char c = ' ';
  12.     char clearChar = ' ';
  13.     printf("輸入二個數字:");
  14.     scanf("%d %d", &n1, &n2);
  15.     while ((clearChar = getchar()) != EOF && clearChar != '\n');/* 清空緩衝區 */
  16.     printf("輸入一個符號:");
  17.     scanf("%c", &c);
  18.     int n3 = 0;
  19.     if (c == '+') {
  20.         n3 = n1 + n2;
  21.     }
  22.     else {
  23.         if (c == '-') {
  24.             n3 = n1 - n2;
  25.         }
  26.         else {
  27.             if (c == '*') {
  28.                 n3 = n1 * n2;
  29.             }
  30.             else {
  31.                 if (c == '/') {
  32.                     n3 = n1 / n2;
  33.                 }
  34.                 else {
  35.                     /* do nothing */
  36.                 }
  37.             }
  38.         }
  39.     }
  40.     A(n3);
  41.  
  42.     printf("\n");
  43.     system("pause");
  44.     return 0;
  45. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×