Skip to content

Instantly share code, notes, and snippets.

@sayantanHack
Last active April 30, 2018 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayantanHack/08039fdfd255317be6b4aafe1c615c22 to your computer and use it in GitHub Desktop.
Save sayantanHack/08039fdfd255317be6b4aafe1c615c22 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<cs50.h>
#include<string.h>
int main(int argc, string argv[])
{
if(argc!=4){
return 1;
}
float s,a = atof(argv[1]),b = atof(argv[3]);
int q;
if(argv[2][0] == '+'){
s = a + b;
printf("The sum is : %f\n",s);
return 0;
}
else if(argv[2][0] == '-'){
s = a - b;
printf("The substraction is : %f\n",s);
return 0;
}
else if(argv[2][0] == 'x'){
s = a * b;
printf("The multiplication is : %f\n",s);
return 0;
}
else if(argv[2][0] == '/'){
s = a / b;
printf("The division is : %f\n",s);
return 0;
}
else if(argv[2][0] == '%'){
q = (int)(a/b);
s = a - (b*q);
printf("The modulo is : %f\n",s);
return 0;
}
else
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment