Skip to content

Instantly share code, notes, and snippets.

@jakariyaa
Last active November 23, 2022 15:09
Show Gist options
  • Save jakariyaa/fc48b411f79374327eef7c70a5f9b2b1 to your computer and use it in GitHub Desktop.
Save jakariyaa/fc48b411f79374327eef7c70a5f9b2b1 to your computer and use it in GitHub Desktop.
#include<stdio.h>
int main()
{
double num1, num2, value;
char sign;
printf("Please enter a basic math expression following two numbers: ");
scanf("%lf %c %lf", &num1, &sign, &num2);
if (sign == '+')
value = num1 + num2;
else if (sign == '-')
value = num1 - num2;
else if (sign == '*')
value = num1 * num2;
else if (sign == '/')
value = num1 / num2;
else
{
printf("\n Input is INVALID! \n Error : %d \n Try : 25 + 25 \n", 420);
return 0;
}
printf("%lf %c %lf = %lf\n", num1, sign, num2, value);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment