We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1cdab47 commit 20e31f8Copy full SHA for 20e31f8
prog.6.8A.c
@@ -0,0 +1,29 @@
1
+/* Program to evaluate simple expressions of the form
2
+ number operator number */
3
+
4
+#include <stdio.h>
5
6
+int main (void)
7
+{
8
+ float value1, value2;
9
+ char operator;
10
11
+ printf ("Type in your expression.\n");
12
+ scanf ("%f %c %f", &value1, &operator, &value2);
13
14
+ if ( operator == '+' )
15
+ printf ("%.2f\n", value1 + value2);
16
+ else if ( operator == '-' )
17
+ printf ("%.2f\n", value1 - value2);
18
+ else if ( operator == '*' )
19
+ printf ("%.2f\n", value1 * value2);
20
+ else if ( operator == '/' )
21
+ if ( value2 == 0 )
22
+ printf ("Division by zero.\n");
23
+ else
24
+ printf ("%.2f\n", value1 / value2);
25
26
+ printf ("Unknown operator.\n");
27
28
+ return 0;
29
+}
0 commit comments