functions demonstartor

This commit is contained in:
tTh 2024-09-17 18:55:04 +02:00
parent 02054433b4
commit 615289b57e

20
code/awk/demo-func.awk Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/awk -f
BEGIN {
print "---- demo fonction ----"
print_sinus(1.0)
print_dist(0.5, 0.5, 0.0)
}
# the simple version
function print_sinus ( value )
{
printf "sin(%f) = %f\n", value, sin(value)
}
# version with local variables.
function print_dist(x, y, z, dist)
{
dist = sqrt(x*x + y*y + z*z)
printf "distance from center = %f\n", dist
}