Computer Science, asked by dhruvilshah9511, 8 months ago

Give an example for defining a function.

Answers

Answered by Anonymous
15

Example: Number of children

We could define a function where the domain X is again the set of people but the codomain is a set of numbers. For example, let the codomain Y be the set of whole numbers and define the function c so that for any person x, the function output c(x) is the number of children of the person x.

Answered by AadilPradhan
1

A function is a set of statements which perform a task or a set of tasks and that can be used again and again with different inputs and outcomes. This makes our code less lengthy and takes less time in comparison to writing different statements for each input by the user.

For example:

/consider all the reqd header files included

int sum(int a , int b, int c)

{ s=a+b+c;

int s;

}

int main()

{

cout<< sum(1,2,3);

cout<<sum(5,6,7);

return 0;

}

Similar questions