Advertisement
18126

HW1 - ex1

Feb 24th, 2022
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int args, char *argv[]) {
  6.     double sum = 0;
  7.     if(args != 4) {
  8.         printf("ERROR\n");
  9.         return 2;
  10.     }
  11.     if(strcmp(argv[2], "+") == 0) {
  12.         sum = atof(argv[1]) + atof(argv[3]);
  13.  
  14.     } else if(strcmp(argv[2], "-") == 0) {
  15.         sum = atof(argv[1]) - atof(argv[3]);
  16.  
  17.     } else if(strcmfp(argv[2], "x") == 0) {
  18.         sum = atof(argv[1]) * atof(argv[3]);
  19.  
  20.     } else if(strcmp(argv[2], "/") == 0) {
  21.         sum = atof(argv[1]) / atof(argv[3]);
  22.     }
  23.     printf("Product = %.2f\n", sum);
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement