Free Essay

C Functions

In:

Submitted By McShady
Words 1748
Pages 7
C Functions

Intended Learning Outcomes
• Distinguish the basic concepts of functions
• Differentiate built-in function to user-defined function • Differentiate the functions that do not return a value and functions that return a value.
• Apply or create function/s to solve problems

Function
• known with various names like a method or a sub-routine or a procedure, etc.
• is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. Two types of function
• Built-in function
– Functions inside the libraries
– Stdio.h -> printf()
– Math.h -> sqrt()

• User-defined function
– Functions that are declared and defined by programmers. Functions
• You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division usually is so each function performs a specific task.

Advantages of user defined functions
1. Helps to decompose the large program into small segments which makes programmer easy to understand, maintain and debug.
2. If repeated code occurs in a program. Function can be used to include those codes and execute when needed by calling that function.
3. Programmer working on large project can divide the workload by making different functions

Advantage

Structured Approach

Method-oriented Approach

Dividing code according to its func1onali1es

Functions
• A function declaration tells the compiler about a function's name, return type, and parameters.
• A function definition provides the actual body of the function.

Defining a functions
• The general form of a function definition in C programming language is as follows
Syntax:

Defining a functions
• The general form of a function definition in C programming language is as follows

Parts of Functions
• Return Type:
– A function may return a value.
– The return_type is the data type of the value the function returns. (datatype: int, char)
– Some functions perform the desired operations without returning a value.

Defining a functions
• The general form of a function definition in C programming language is as follows

Parts of Functions
• Function Name
– This is the actual name of the function.
– The function name and the parameter list together constitute the function signature
– Starts with small letters and a verb
– E.x. computeAge(), printName()

Defining a functions
• The general form of a function definition in C programming language is as follows

Parts of Functions
• Parameters
– A parameter is like a placeholder.
– When a function is invoked, you pass a value to the parameter.
– This value is referred to as actual parameter or argument. – The parameter list refers to the type, order, and number of the parameters of a function.
– Parameters are optional; that is, a function may contain no parameters.
– ex. Void computeAge(int byear)

Defining a functions
• The general form of a function definition in C programming language is as follows

Parts of Functions
• Function Body
– The function body contains a collection of statements that define what the function does.

Example: function definition

Example:

same DATA TYPE

Function Declarations
• A function declaration tells the compiler about a function name and how to call the function.
• The actual body of the function can be defined separately • Function declaration is required when you define a function in one source file and you call that function in another file. In such case you should declare the function at the top of the file calling the functions

Function Declarations

Calling a Function
• While creating a C function, you give a definition of what the function has to do. To use a function, you will have to call that function to perform the defined task

Calling a Function
• When a program calls a function, program control is transferred to the called function.
• A called function performs defined task, and when its return statement is executed or when its function-ending closing brace is reached, it returns program control back to the main program.

Calling a Function:Example

Output:
• max() function along with main() function and compiled the source code. While running final executable, it would produce the following result:
Max value is : 200

Example 2
• A program that will compute the age of user by the given birth year.
• Formula?

Age = 2015 – birth Year

Solution1

Take note: if the return type is not void,

it should have a return at the end of your funcAon

Solution2

Take note: if the return type is void, No return is needed

What’s the output?

Passed! 93

Assume num1=4, num2=5

N1 = 5, n2 = 4 Answer: 29

Example 4

Void cannot be placed inside prin6,

nothing to return

Will not compile

Solution

The square root: 25

Function Arguments
• it must declare variables that accept the values of the arguments.
• These variables are called the formal parameters of the function.
• The formal parameters behave like other local variables inside the function and are created upon entry into the function and destroyed upon exit.

Output
• if num1 = 1
– Sum is 7

• If num1 = 2
– Product is 12

• Note: you can place method inside another method. Two ways

• Function call by value
• Function call by reference Function call by value
• The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.

Function call by value
• By default, C programming language uses call by value method to pass arguments. In general, this means that code within a function cannot alter the arguments used to call the function. Consider the function swap() definition as follows.

Function call by value
• Consider the function swap() definition as follows. Function call by value
• Consider the function swap() definition as follows. Result:
Before swap, value of a: 100
Before swap, value of b: 200
After swap, value of a: 100
After swap, value of b: 200

Two ways

• Function call by value
• Function call by reference Function call by reference
• The call by reference method of passing arguments to a function copies the address of an argument into the formal parameter.
Inside the function, the address is used to access the actual argument used in the call.
• This means that changes made to the parameter affect the passed argument.

Function call by reference
• To pass the value by reference, argument pointers are passed to the functions just like any other value. So accordingly you need to declare the function parameters as pointer types as in the following function swap(), which exchanges the values of the two integer variables pointed to by its arguments. Result:

C Variable Declarations
• Local
• Global
• Formal Parameters

Local Declaration
• declared inside a function or block
• They can be used only by statements that are inside that function or block of code.

C Variable Declarations
• Local
• Global
• Formal Parameters

Global Declaration
• defined outside of a function, usually on top of the program.
• hold their value throughout the lifetime of your program and they can be accessed inside any of the functions defined for the program. Global Declaration
• can be accessed by any function.
• is available for use throughout your entire program after its declaration.

Global Declaration
• can be accessed by any function.
• is available for use throughout your entire program after its declaration.

C Variable Declarations
• Local
• Global
• Formal Parameters

Formal Parameters
• are treated as local variables within that function and they will take preference over the global variables.

Formal Parameters

Result:FP

Common Programming Errors
1. It is an error to write a C program without a function named main.
2. It is wrong to define functions with the same name in the same program.

Common Programming Errors
3. There should be no semicolons in a function’s header. Thus, the following is wrong. void something(int x, double y);
{
...
}

Common Programming Errors
4. It is an error to define a function inside another. Therefore, it is wrong to write void something(int x, double y)
{
... void anything(char z)
{
...
}
}

C Function: FAQ
1. What is a function?
In computer programming, functions are also called subprograms. A function consists of a groups or sequence of statements.

C Function: FAQ
2. What types of function are there in C?
There are two types of functions, namely: v pre-defined – those functions that have been written for us (by some other programmers); examples are scanf and printf v user-defined – those functions that we are going to write/implement

C Function: FAQ
3. How do you invoke/call a function that has already been defined?
A function that has been defined by the user is invoked by giving its name and its parameters.

C Function: FAQ
4. Can you call a function inside another function (besides main)?
Yes, any function can be called inside any function. Refrain from invoking a function inside a function with the same name. This will not be a syntactical error, but there are issues that should be resolved first (to be discussed in the next course). In the same way, do not call the function main within any function

C Function: FAQ
5. Can you have a return a value through the function name in a void function?
No. A warning will be generated.
6. Can you have more than one return statement within a function?
Yes. However, only one (1) return statement will be executed only. After executing the return statement, control is returned to the calling function.

Many return statements

C Function: FAQ
7. Can you return more than one value through the function name?
No. A function name is an identifier.
Similar to a variable, a function name can hold only one value at a time

C Function: FAQ
8. Does it matter what name you use in the parameter? No. The parameter need not be the same identifier that we used in the calling function.
What matters is the number of parameters, their respective data types, and their sequence. Final Project
• 5 members in a group
• Transactional based system
– Inventory system
– Reservation system
– POS system
– Ticketing system
(no repetition of system)

• Submit your groupings to your leader
• We will get this on your Lab classes

Assignment #1 finals
• Create a program that will guess the number. • Display higher if the input value is higher than the defined number, otherwise lower
• if the input matches the defined number display “congrats!” ask the user if he/she wants to play again. If yes, go back to guessing game
• Create your own function

Similar Documents

Free Essay

Debugging of C++ Function

...Debugging of a function Consider the find_max() function given below: /** Finds the largest value in array elements x[start] through x[last]. pre: first <= last. @param x Array whose largest value is found @param start First subscript in range @param last Last subscript in range @return The largest value of x[start] through x[last] */ 1. int find_max(int x[], int start, int last) { 2. if (start > last) 3. throw invalid_argument("Empty range"); 4. int max_so_far = 0; 5. for (int i = start; i < last; i++) { 6. if (x[i] > max_so_far) 7. max_so_far = i; 8. } 9. return max_so_far; 10.} ------------------------------------------------- The function will take 3 arguments, an array, starting value and last value and calculates the maximum value and return from where the function has been called. This code does not work properly. In order to understand the working of the code, output statements should be added into the code. The output statements that will be needed in the above function should be inside for loop and after the lines 5, 7 and 9. After including the diagnostic statements, the code can be given as: /** Finds the largest value in array elements x[start] through x[last]. pre: first <= last. @param x Array whose largest value is found @param start First subscript in range @param last Last subscript in range @return The largest value of x[start] through x[last] */ int...

Words: 463 - Pages: 2

Premium Essay

Rubric

...2. A club has 25 members. A.) a) How many ways are there to choose four members of the club to serve on an executive committee? 12650 B.) b) How many ways are there to choose a president, vice president, secretary, and treasurer of the club, where no person can hold more than one office? 303600 4. In how many different ways can five elements be selected in order from a set with three elements when repetition is allowed? 243 5. What is the probability that a fair die never comes up an even number when it is rolled six times? 0.016+- 0.001 (Note: Enter the value of probability in decimal format and round it to three decimal places.) 6. Let p and q be the propositions p: You have the flu. q: You miss the final examination. Identify an English translation that expresses the compound proposition p → q. * If you miss the final exam then you have the flu. * If you have the flu, then you miss the final exam. * If you have the flu, then you will not miss the final exam. * If you don't have the flu, then you miss the final exam. 7. Let q and r be the propositions q: You miss the final examination. r: You pass the course. An English translation of the compound proposition ¬q ↔ r is "You do not miss the final exam if and only if you pass the course." * Yes * No 8. Let q and r be the propositions q: You miss the final examination. r: You pass the course. An English translation of the compound proposition q → ¬r is "If you miss the final exam, then you pass the course...

Words: 3659 - Pages: 15

Free Essay

Haha

...systems in which there is change and a way to deduce the predictions of such models; Calculus provides a way for us to construct relatively simple quantitative models of change and to deduce their consequence. By studying this, you can learn how to control the system to do make it do what you want it to do. CHAPTER 1: FUNCTIONS AND LIMITS FUNCTIONS * A bunch of ordered pairs of things with property that the first members of the pairs are all different from one another. Ex [ {1,1,}, {2,1}, {3,2} ] Arguments – first number of the pair Domain – whole set Values – Second number of the pair Range – set of values Classification of functions 1. Linear Functions – “steepness of the line” w/c can go uphill or downhill.  y = mx + b 2. Quadratic Functions – it has a degree and forms a parabolic path. The highest (or lowest point) of the parabola is called the vertex. At has a form of (standard form of quadratic equation) F(x) = Ax2 + Bx + C where A, B,C are constant. Vertex form of Quadratic F(x) = a (x-h)2 + K Quadratic Formula 3. Polynomial Functions – a quadratic, a cubic, a quartic and so on involving only non-negative...

Words: 349 - Pages: 2

Premium Essay

Computer Vscience

...2009 ! Module 1: Functions 1 1.1 Objectives: In this module: We introduce with examples, the concept of a function and study some classes of functions. We discuss methods of nding the domain, range, zeros and singularities of some real-valued functions. We look at injective (one to one) and surjective (onto) functions and end the module by exploring the inverse of a function and the composition of functions. We stimulate students through classroom and other interactive activities to understand the concept of a function and then discover the di erences and similarities between the several types of functions introduced. 2 1.2 Learning Outcomes: At the end of this module students should be able to De ne a function; identify di erent types of functions and Identify relations which are not functions; Identify di erent classes of functions, nd the domain and range that makes a rule f (say), a function; Investigate the injectiveness, surjectiveness and the inverse of di erent functions; Establish the composition of two or more functions. 3 1.3 Learning Activities: Students should: 1 Explore notes and exercises, individually and in groups; Explore and use related materials on the Intranet, especially the e-granary and MIT open course ware; Explore and use related materials on the OLI Calculus course on the Internet(http://www.cmu.edu/OLI/courses/); Solve relevant questions from past MTH103 Examinations. 4 1.4 Introduction A function is the means by...

Words: 18670 - Pages: 75

Free Essay

War on Drugs

...MCR 3U Exam Review Unit 1 1. Evaluate each of the following. a) b) c) 2. Simplify. Express each answer with positive exponents. a) b) c) 3. Simplify and state restrictions a) b) c) d) 4. Is Justify your response. 5. Is Justify your response. Unit 2 1. Simplify each of the following. a) b) c) 2. Solve. a) b) c) 3. Solve. Express solutions in simplest radical form. a) b) 4. Find the maximum or minimum value of the function and the value of x when it occurs. a) b) 5. Write a quadratic equation, in standard form, with the roots a) and and that passes through the point (3, 1). b) and and that passes through the point (-1, 4). 6. The sum of two numbers is 20. What is the least possible sum of their squares? 7. Two numbers have a sum of 22 and their product is 103. What are the numbers ,in simplest radical form. Unit 3 1. Determine which of the following equations represent functions. Explain. Include a graph. a) b) c) d) 2. State the domain and range for each relation in question 1. 3. If and , determine the following: a) b) 4. Let . Determine the values of x for which a) b) Recall the base graphs. 5. Graph . State the domain and range. Describe...

Words: 940 - Pages: 4

Premium Essay

Always Try Your Best

...Jump to: navigation, search This article is about the branch of mathematics. For other uses, see Calculus (disambiguation). | It has been suggested that Infinitesimal calculus be merged into this article or section. (Discuss) Proposed since May 2011. | Topics in Calculus | Fundamental theorem Limits of functions Continuity Mean value theorem [show]Differential calculus  | Derivative Change of variables Implicit differentiation Taylor's theorem Related rates Rules and identities:Power rule, Product rule, Quotient rule, Chain rule | [show]Integral calculus  | IntegralLists of integrals Improper integrals Integration by: parts, disks, cylindrical shells, substitution, trigonometric substitution, partial fractions, changing order | [show]Vector calculus  | Gradient Divergence Curl Laplacian Gradient theorem Green's theorem Stokes' theorem Divergence theorem | [show]Multivariable calculus  | Matrix calculus Partial derivative Multiple integral Line integral Surface integral Volume integral Jacobian | | Calculus (Latin, calculus, a small stone used for counting) is a branch of mathematics focused on limits, functions, derivatives, integrals, and infinite series. This subject constitutes a major part of modern mathematics education. It has two major branches, differential calculus and integral calculus, which are related by the fundamental theorem of calculus. Calculus is the study of change,[1] in the same way that geometry is...

Words: 6472 - Pages: 26

Premium Essay

Relations-Seqences-Functions-Graph

... * Patriots – Tom Brady * Rams – Joe Namath * Chiefs – Joe Montana 1. Using D as the domain and Q as the range, show the relation between the 2 sets, with the correspondences based on which players are on which team. Show the relation in the following forms: Set of ordered pairs (20 points) Directional graph (like the pictures draw in class in our live chats – see HINT below). (20 points) The ordered pairs when D is the domain are:  {(Jets,Joe Namath),(Giants,Eli Manning),(Cowboys, Troy Aikman),(49ers,Joe Montana),(Patriots,Tom Brady),(Rams,Joe Namath),(Chiefs, Joe Montana)} 2. Is the relation a function? Explain. (10 points) This is a function, because every element (Quarterback) of the domain  is mapped to exactly one unique element (Team) of the range. So with the one to one relation of player to team, that makes this a function. 3. Now, use set Q as the domain, and set D as the range (reverse). Show the relation in the following forms: Set of ordered pairs (20 points) Directional graph (20 points) The ordered pairs when Q is the domain are:  {(Joe Namath, Jets),(Eli Manning, Giants),( Troy Aikman, Cowboys),( Joe Montana,49ers,),(Tom Brady, Patriots),(Joe Namath, Rams),(Joe...

Words: 580 - Pages: 3

Free Essay

Systems of Linear Equations

...1. Identify the graph that represents the system of linear equations. [pic] |A. |[pic] |C. |[pic] | | | | | | |B. |[pic] |D. |[pic] | 2. The graph below shows the cost (c), in dollars, to rent a boat for h hours at two different boat companies. [pic] At what number of hours will the cost to rent a boat be the same at both companies? F. 4 G. 5 H. 8 J. 20 3. John and Patrice are each saving money to buy a car. John has $750 saved and will save an additional $30 a week. Patrice has $1,200 saved and will save an additional $20 a week. How many weeks will it take John and Patrice to save the same amount of money? A. 39 weeks B. 40 weeks C. 45 weeks D. 55 weeks 4. Choose the equation wherein you would isolate a variable easily so that substitution method can be used to solve the linear system. [pic] F. Equation 1 G. Equation 2 H. Neither Equation 1 nor Equation 2 J.   Both Equation 1 and Equation 2 5. Solve the linear system. [pic] A. (5, 7) B. (5, 8) C. (6, 7) D. (6, 8) 6. Which of the following ordered pairs satisfies the linear system? [pic] F. (-11, - 5) G. (-11, 5) H. (-5,...

Words: 1338 - Pages: 6

Free Essay

Exam

... a.|-7/2| b.|-6| c.|6| d.|12/15| ____ 2. Which property best describe the following statement? a.|distributive property| b.|associative property| c.|transitive property| d.|commutative property| ____ 3. Simplify a.||c.|| b.||d.|| ____ 4. Which graph below represents a function? a.||c.|| b.||d.|| ____ 5. What is the domain of the given function? a.| |c.|| b.||d.|| ____ 6. Use the distributive property to simplify the expression: . a.|| b.|| c.|| d.|| ____ 7. Which of the following is not a function? a.||c.|| b.||d.|| ____ 8. Choose the correct algebraic translation of “ 3 more than twice a number is three times the sum of the number and 5”. a.|| b.|| c.|| d.|| ____ 9. Which statement illustrate the symmetric property? a.|| b.|If 3 + 2 = 5 and 5 = 4 + 1 thenn 3 + 2 = 4 + 1| c.|If 3 + 2 = 5 then 5 = 3 + 2| d.|3 + 2 = 5| ____ 10. Translate the verbal phrase below into its mathematical representation. “ Six decreased by three times the sum of two and four times a number is one.” a.|6 - 3 + 2 + 4n = 1| b.|6 - 3 2 + 4n = 1| c.|3(2 + 4n) -6 =1 | d.|6 - 3(2 + 4n) = 1| ____ 11. Simplify a.|| b.|| c.|| d.|| ____ 12. A function, has a domain of {-6, -2, 3}. What is its range? a.|{-12, -8, 4}| b.|{-42, -22, 3}| c.|{-8, -6, 12}| d.|{-10...

Words: 660 - Pages: 3

Free Essay

Teaching Assignment System

...teaching capabilities. This system will help the faculty so that each subject can be assigned efficiently without the tedious manual assigning system. The Teaching Assignment System requires an online system with a database keeping the subjects and the trimester’s information; the online system needs to have * User friendliness for computer illegitimate * Easy to maintain by system administrators. Target User The main target user for this Teaching Assignment System will be the lecturer, dean or the faculty. This system can be very useful for: a. Faculty for designing new subjects based on associated trimester. b. Lecturers who would like to add in information on subjects that they prefer to teach for a particular semester. c. Dean who would like to analyze or view in detail about the trimester or subjects being thought to track semester progress. Plan Milestone Gant chart Literature Review Users 1. Lecturer : They are able to view the subjects for that semester and subjects that have been assigned to them. They will be able to update their preferences and the history of the subject that has been taught by them and also add in some remarks if needed. 2. Committee: The committee will be able to assign the coordinators for the subjects being thought for that semester. The committee board will also be able...

Words: 2436 - Pages: 10

Free Essay

Complex Analysis

...Im(z) = (z - ) When z is real, z = x then z = Polar Form of Complex Numbers Let (x,y) be the Cartesian coordinates and (r,Ө) be the polar coordinates,then x = r cos Ө , y = r sin Ө Therefore, z = x+iy = r (cos Ө+ isin Ө) r = which is the absolute value or the modulus of z. Ө = arg z = tan which is the argument of z. Important Properties Generalized Triangle Inequality : Let Then, De Moivre’s formula : Nth Root of z : Limit, Continuity and Derivatives of Function of Complex variable: Limit : Let the function of a complex variable : w = f(z) = f(z+iy) = u(x,y)+iv(x,y). A function f(z) has a limit l at if exists. Continuity : A function f(z) has a continuity at z0 , if f(z0) is defined and Derivative : A function f(z) is differentiable at z0 , if exists. Moreover, f(z) has a derivative at z0. If the function is...

Words: 1261 - Pages: 6

Free Essay

Marketinf Mix

...Practical 5: Simple functions 1. Write one program to accept two input values x and y and find the values of the following: (a) [pic] (b) [pic][pic] (c) [pic] (d) [pic] (e) [pic] (NOTE: log10(x) function is used to calculate log10x) #include #include int main() { int x,y ; double a,b,c,d,e; printf("Enter 2 integer :\t"); scanf("%d%d",&x,&y); //calculation a=sqrt(x*y); b=(sqrt(x))*(sqrt(y)); c=pow(x,y); d=pow(y,x); e=log10(pow(x,y)); printf("%lf\n",a); printf("%lf\n",b); printf("%lf\n",c); printf("%lf\n",d); printf("%lf\n",e); return 0; } 2. Write a program that prompts the user for the Cartesian coordinates to two points [pic]and [pic] and display the distance between them computed using the following formula: distance = [pic] #include #include int main() { int x1,x2,y1,y2 ; double dis ; printf("Enter 4 integer :\t"); scanf("%d%d%d%d",&x1,&x2,&y1,&y2); //calculation dis=sqrt(pow(x1-x2,2))+(pow(y1-y2,2)); printf("The distance is %.2lf\n",dis); return 0; } 3. Write a program to compute and display the absolute difference of two type double variables, x and y (that is | x - y |). #include #include int main () { double x...

Words: 413 - Pages: 2

Free Essay

Warrior Cups

...πr³ 900 = πr²(h + 2/3r) 900/ πr² = h + 2/3r (900/ πr²) – 2/3r = h Cost in terms of r : C(r) = 0.05(2 πrh + πr²) + 0.10(2 πr²) = 0.1 πrh + 0.05 πr² +0.2 πr² = 0.1 πr(900/ πr² - 2r/3) + 0.25 πr² *insert h = 90 πr/ πr² - 0.2 πr²/3 + 0.25 πr² = 90/r + 1.1 πr²/6 C’(r) = -90/r² + 1.1 πr/3 * take derivative 0 = -90/r² + 1.1 πr/3 * set derivative equal to zero r²(0) = (-90/r² + 1.1 πr/3) r² *multiply both sides by r² 0 = -90r²/r² + 1.1 πr³/3 = -90 + 1.1 πr³/3 r = (90/1.1 π)^1/3 r ≈ 4.27cm Therefore, the radius is approximately 4.27cm Double derivative Check: C’’(r) = 1.1 πr² C’’(4.27) = +ve Therefore it is a minimum Finding height: h = 900/ π(4.27)² - 2/3(4.27)*plug the radius into the height equation h = 12.87 Therefore the height is 12.87cm Dimensions and Cost: * r = 4.27cm * h = 12.87 cm * V = 900 cm³ * Lid Plastic: ¢0.10/cm² * Cup Plastic: ¢0.05/cm² Demand function: X = 100,000 -5,000n n = 100,000 – x/5,000 *Isolate for n variable P = 0.99 + 0.10n P(x) = 0.99 + 0.10(100,000 – x/5,000) *plug in n value = 0.99 + 2 – 0.00002x = 2.99 – 0.00002x X = # of $0.10 increases Revenue Function: R(x) = xp(x) R(x) = 2.99x – 0.00002x² R’(x) = 2.99 – 0.00004x Cost Function: C = -0.0000004x² + 0.316x + 2000 C’ = -0.0000008x² + 0.316 Profit Function: P = (2.99x – 0.00002x²) – (-0.0000004x² + 0.316x + 2000) = -0.0000196x² + 2.674x – 2000 P’...

Words: 355 - Pages: 2

Premium Essay

546 Quantative

...Name: Bekenov Kuandyk Assignment 1 1. Prove that fx=2x+5 is one-to-one function. (10 points) Let make an assumption tha fx1=fx2t and then prove that x1=x2. fx1=fx2=2x1+5=2x2+5→x1=x2 , Then fx=2x+5 is one-to-one function 2. B B A A Let f: A→B, as given below. Is f a one-to-one function? Please explain why or why not. (10 points) f f 5 5 5 5 1 1 3 3 1 1 6 6 2 2 2 2 4 4 6 6 7 7 4 4 8 8 3 3 F is not one-to-one function, because f(1)=1 and f(2)=1. 3. The modulo function (a mod n or a modulo n) maps every positive integer number to the remainder of the division of a/n. For example, the expression 22 mod 5 would evaluate to 2 since 22 divided by 5 is 4 with a remainder of 2. The expression 10 mod 5 would resolve to 0 since 10 is divisible by 5 and there is not a remainder. a. If n is fixed as 5, is this function one-to-one? (5 points) F(n mod 5) is not one-to-one function, because f(n mod 5)= between 0 and 4. It means that we have the same image of F for different n (integer). b. List five numbers that have the exact same image. (5 points) 12, 17, 22, 27, 32 4. Find limn→∞n2-1n3+n (6 points) limn→∞n2-1n3+n=limn→∞n2n3-1n3n3n3+nn3=0-01+0=0 5. Find limx→∞x1001-xx1000+x (6 points) limx→∞x1001-xx1000+x=limx→∞1-1x10001x+1x1000=1-00+0=∞ 6. Find limx→∞8x6+4x4-3x2x6+x5-7 (6 points) limx→∞8x6+4x4-3x2x6+x5-7=limx→∞8+4x2-3x52+1x-7x6=8+0-02+0-0=4 ...

Words: 746 - Pages: 3

Premium Essay

Biojjb

...Basics Rounding to Decimal Places If the next number is below 5, round down by leaving thr previous digit untouched. Round 15.283 correct to 2 decimal places. The answer is 15.28 If the next number is 5 or more, round up Round 3.728 correct to 2 decimal places. The answer is 3.73 Rounding to significant figures For numbers between 0 and 1, start counting the significant figures from the first non-zero digit. Round 0.007851 correct to 2 significant figures. The answer is 0.0079 For numbers larger than 1, start counting the significant figures from the first digit. Round 583 200 correct to 2 significant figures. The answer is 580 000 Scientific notation. 13450700 in scientific notation is 1.34507  10 0.00125 in scientific notation is 1.25  10 7 3 Addition   Sum Subtraction   Difference Multiplication   *  : /  Product Division  Quotient Numbers Real Numbers Rational Numbers Irrational Numbers Definition of a rational number. are not rational. They are non-terminating & non-recurring decimals. A number is rational if it can be expressed as a fraction in p the form q ,where p & q have no common factor and q  0. Examples 2 8 Fractions, e.g. 3 , 17 Integers, e.g. 2 , 3, 15 Terminating decimals, e.g. 0.3562    Recurring decimals, e.g. 0.4 , 0.23, 0.17 Examples  , e. Surds, e.g. 2 , 3 5 . Transcendental numbers, e.g. 0.100100010000100.... Recurring...

Words: 8924 - Pages: 36