SHARE
TWEET

四則演算:二項

YUPPUN Apr 19th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include <stdlib.h>
  4. int main(void){
  5.     int kou1;
  6.     char enzan = 0;
  7.     int kou2;
  8.     char eq;
  9.     int ans = 0;
  10.     scanf( "%d%c%d%c", &kou1, &enzan, &kou2, &eq );
  11.     if (enzan == 0x2b){
  12.       ans = kou1 + kou2;
  13.     } else if (enzan == 0x2d){
  14.       ans = kou1 - kou2;
  15.     } else if (enzan == 0x2a){
  16.       ans = kou1 * kou2;
  17.     } else if (enzan == 0x2f){
  18.       ans = kou1 / kou2;
  19.     } else {
  20.       printf("Error! Please check your fomula.\n");
  21.       exit(0);
  22.     }
  23.     printf("%d\n",ans);
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top