Skip to content

Instantly share code, notes, and snippets.

@JubbaSmail
Created November 13, 2014 10:57
Show Gist options
  • Select an option

  • Save JubbaSmail/a907f0c83e5631c46a3f to your computer and use it in GitHub Desktop.

Select an option

Save JubbaSmail/a907f0c83e5631c46a3f to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(int argc, char *argv[])
{
if (argc != 4) {
printf("Usage: exe num1 opr num2\n");
return 1;
}
int x = strtol(argv[1]);
int y = strtol(argv[3]);
int z = 0;
if (strcmp(argv[2],"+") == 0 )
z = x + y;
else if (strcmp(argv[2], "-") == 0)
z = x - y;
else if (strcmp(argv[2], "*") == 0)
z = x * y;
else if (strcmp(argv[2], "/") == 0)
z = x / y;
printf("%d\n", z);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment