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 98db624 commit e41f105Copy full SHA for e41f105
prog.8.7.c
@@ -0,0 +1,35 @@
1
+// Function to calculate the absolute value
2
+
3
+#include <stdio.h>
4
5
+float absoluteValue (float x)
6
+{
7
+ if ( x < 0 )
8
+ x = -x;
9
10
+ return x;
11
+}
12
13
+int main (void)
14
15
+ float f1 = -15.5, f2 = 20.0, f3 = -5.0;
16
+ int i1 = -716;
17
+ float result;
18
19
+ result = absoluteValue (f1);
20
+ printf ("result = %.2f\n", result);
21
+ printf ("f1 = %.2f\n", f1);
22
23
+ result = absoluteValue (f2) + absoluteValue (f3);
24
25
26
+ result = absoluteValue ( (float) i1 );
27
28
29
+ result = absoluteValue (i1);
30
31
32
+ printf ("%.2f\n", absoluteValue (-6.0) / 4 );
33
34
+ return 0;
35
0 commit comments