0 valutazioniIl 0% ha trovato utile questo documento (0 voti)
8 visualizzazioni3 pagine
This document discusses functions in C++ programming. It defines a function as a relation between inputs and outputs where each input relates to exactly one output. It provides a sample C++ program that defines an integer subtraction function and calls it multiple times with different arguments, outputting the results each time to demonstrate that a function can be called and reused. The program subtracts values, outputs the results, and in one case adds a result to another value to further demonstrate function usage.
This document discusses functions in C++ programming. It defines a function as a relation between inputs and outputs where each input relates to exactly one output. It provides a sample C++ program that defines an integer subtraction function and calls it multiple times with different arguments, outputting the results each time to demonstrate that a function can be called and reused. The program subtracts values, outputs the results, and in one case adds a result to another value to further demonstrate function usage.
This document discusses functions in C++ programming. It defines a function as a relation between inputs and outputs where each input relates to exactly one output. It provides a sample C++ program that defines an integer subtraction function and calls it multiple times with different arguments, outputting the results each time to demonstrate that a function can be called and reused. The program subtracts values, outputs the results, and in one case adds a result to another value to further demonstrate function usage.
Function- is a relation between a set of inputs and a set of
permissible outputs with the property that each input is related to exactly one output.
http://en.wikipedia.org/wiki/Function_
C++ Sample Program of Function
A function can actually be called multiple times within a program, and its argument is naturally not limited just to literals: #include <iostream> using namespace std; int subtraction (int a, int b) { int r; r=a-b; return r; } int main () { int x=5, y=3, z; z = subtraction (7,2); cout << "The first result is " << z << '\n'; cout << "The second result is " << subtraction (7,2) << '\n'; cout << "The third result is " << subtraction (x,y) << '\n'; z= 4 + subtraction (x,y); cout << "The fourth result is " << z << '\n'; }
The first result is 5
The second result is 5 The third result is 2 The fourth result is 6