Are functions in mathematics similar to functions in programming. Am I right yes or no?

# Functions in programming

Exactly the same.

In mathematics I give a function an input and the function does itâ€™s â€śthingâ€ť and hands me back an output.

Functions are similar in programming

Think of a function that squares a number

```
int square(int n) {
return n*n
}
```

You give the function itâ€™s input â€śnâ€ť

from there the function mutates n by multiplying it by itself

it returns this new output to you.

Not so. Similar in an anologous way, but not exact.

Functions in programming are **re-usable code blocks** that can take any form. In maths they refer to variation of `y`

in terms of `x`

.

```
y = f(x)
```

`y`

varies as `x`

according to the relationship defined in the equation.

```
f(x) = ax + b
```

where `a`

and `b`

are fixed, and `x`

is the independent variable. When `f(x)`

returns more than one value for `y`

for one input of `x`

, it is no longer a *function*, but a *relation*.

Take for instance a standard quadratic,

```
f(x) = ax^2
```

which produces a parabola centered about the original and reflected off the `y`

axis. Each value of `x`

yields only one value for `y`

. If we rotate the graph 90 degrees clockwise or counterclockwise it is no longer a function since we get two values for `y`

for one value of `x`

.

```
x = ay^2
```

which *when* we solve for `y`

, becomes,

```
y = +/-(x / a) ^ 0.5
```

As we can see, there are now two solutions.

We can write program functions that emulate maths, but that is where the similarity ends.

Is the definition of return to give something back as an answer? Am I right yes or no?

More or less, yes. A return is the response of the function to the caller. The caller is in a scope different from the function, and return bridges the scope gap.

I want to create a site and I find it difficult to create a site without taking a model I canâ€™t apply what I learnt before can you help me?