Skip to content

Commit e41f105

Browse files
committed
value copied into formal parameter
1 parent 98db624 commit e41f105

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

prog.8.7.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
printf ("result = %.2f\n", result);
25+
26+
result = absoluteValue ( (float) i1 );
27+
printf ("result = %.2f\n", result);
28+
29+
result = absoluteValue (i1);
30+
printf ("result = %.2f\n", result);
31+
32+
printf ("%.2f\n", absoluteValue (-6.0) / 4 );
33+
34+
return 0;
35+
}

0 commit comments

Comments
 (0)