Logic of Mathematics (College Algebra for Computer Science)

download Logic of Mathematics (College Algebra for Computer Science)

of 69

Transcript of Logic of Mathematics (College Algebra for Computer Science)

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    1/69

    [1]

    Table of Contents

    PREFACE .............................................................................................. 4

    SETS .................................................................................................... 5

    Kinds of Sets ................................................................................... 6

    Finite Sets ................................................................................... 6

    Infinite Sets ................................................................................. 6

    Universal Sets ............................................................................. 7

    Null Sets ...................................................................................... 7

    Relationship of Sets ........................................................................ 7

    Equal Sets ................................................................................... 7

    Equivalent Set ............................................................................. 8

    Joint Sets ..................................................................................... 8

    Disjoint Sets ................................................................................ 9

    Subsets ........................................................................................ 9

    Set Operations .............................................................................. 10

    Union ........................................................................................ 10

    Intersection............................................................................... 10

    Difference ................................................................................. 11

    Complement ............................................................................. 11

    Set Product ............................................................................... 12

    Venn-Euler Diagram ..................................................................... 12

    REAL NUMBERS ................................................................................ 21

    Kinds of Real Numbers ................................................................. 21

    Rational Numbers ..................................................................... 21

    Integers ..................................................................................... 22

    Natural Numbers ...................................................................... 22

    Whole Numbers ........................................................................ 22

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    2/69

    [2]

    Fractions ................................................................................... 22

    Decimal Numbers ..................................................................... 23

    Irrational Numbers ................................................................... 23

    Properties of Real Numbers ......................................................... 23

    Closure ...................................................................................... 24

    Commutative ............................................................................ 24

    Associative ................................................................................ 24

    Distributive ............................................................................... 25

    Identity ..................................................................................... 25

    Inverse ...................................................................................... 26

    Reflexive ................................................................................... 26

    Symmetric ................................................................................. 27

    Transitive .................................................................................. 27

    Substitution .............................................................................. 28

    Addition .................................................................................... 28

    Multiplication ........................................................................... 29

    ALGEBRAIC EXPRESSIONS ................................................................. 37

    Polynomials .................................................................................. 37

    Some Terms: ............................................................................. 37

    Operations on Polynomials ...................................................... 39Special Products ....................................................................... 40

    Binomial Theorem .................................................................... 41

    Pascal Triangle .......................................................................... 41

    Factoring ................................................................................... 42

    RADICALS .......................................................................................... 50

    Laws of Radicals ............................................................................ 50

    Operations on Radicals ................................................................. 51

    Addition .................................................................................... 51

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    3/69

    [3]

    Multiplication ........................................................................... 51

    LINEAR, LITERAL AND WORD PROBLEMS ......................................... 57

    Linear Equations and Inequalities ................................................ 57

    Literal Equations ........................................................................... 57

    Word Problems ............................................................................. 58

    Kind of Word Problems ............................................................ 58

    QUADRATIC EQUATIONS AND INEQUALITIES .................................. 65

    Laws of Quadric Equations ........................................................... 65

    Quadratic Formula ........................................................................ 66

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    4/69

    [4]

    PREFACE

    This module entitled Logic of Mathematics is designed primarily

    to enrich the psychology of students of Bachelor of Science in Computer

    Science enrolled in College Algebra concerning the importance of

    studying Mathematics in general and College Algebra in particular. This

    module uses several sources to present unquestionable credibility of its

    contents. In addition, this module withholds several manipulations in

    order to clearly manifest its mission and suit the needs of the students.

    Preliminary knowledge about Algebra and Turbo C

    Programming Language is necessary to fully comprehend the contentsof this module. Moreover, this module used direct approach in

    correlating Mathematics in the Science of Computers. Vivid examples

    are provided so that there is enough illustration to present the ideals of

    Mathematics in Computer Studies. Furthermore, activities are available

    at the end of each chapter to measure and evaluate whether the

    student got the necessary understanding before proceeding to the next

    chapter.

    This module will be the start of your upcoming success in the

    field of Computer Science aided by the logic of Mathematics. As what

    the Our Lady of Fatima University claims, rise to the top!

    James Michael A. Adoremos

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    5/69

    [5]

    SETS

    A set is a well-defined collection of data. The data mentioned

    could be anything like objects, numbers, letters and the like repeated or

    not. Data belonging to a set are referred to as its elements.

    In computer, a set refers to a variable which contains several

    values. These are then called array. Arrays are declared like regular

    variables just that they have the symbols [] right after the last letter of

    the variable name wherein there is a specified limit of maximum values

    an array can hold placed in between the symbols []. Elements, on the

    other hand, are referred to as its values. It starts its index at zero.

    Mathematics:

    A = { 1, 2, 3, 4, 5 }

    Here a set named A has the elements 1, 2, 3, 4, 5.

    Computer:

    int A[5] = { 1, 2, 3, 4, 5}

    Here an integer array has the values 1, 2, 3, 4, 5.

    Sets and arrays are treated the same. Their use and function in

    both Mathematics and Computer are similar.

    The next lessons on these chapter focuses on Mathematics as they

    are not generally used in Computer Programming.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    6/69

    [6]

    Kinds of Sets

    Finite Sets

    Finite Sets are sets in which all of their elements are

    enumerated.

    Here is an example:

    A = { 1, 2, 3, 4 }

    B = { x | x is a letter in the word MISSISSIPPI }

    The cardinal number of a finite set is the unique countingnumber n such that the elements of a set are in one-to-one

    correspondence with the elements of a set of counting numbers from 1

    to n. One-to-one correspondence refers to the circumstance where

    every element of a set is paired with one and only one element of

    another set. It follows the format:

    n(NAMEOFSET)Where:

    NAMEOFSET is the name of the reference set.

    Furthermore, n(A), for example, is read as n of A or the cardinal

    number of A. And take note that the cardinal number of a null set is

    always zero.

    Infinite Sets

    Infinite Sets are sets in which not all of the elements are

    enumerated.

    Here is an example:

    A = { 1, 2, 3, 4 }

    B = { x | x is a letter in the word MISSISSIPPI }

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    7/69

    [7]

    Universal Sets

    Universal Sets are sets whose elements are the elements of all

    of the sets under consideration. Common elements are regarded as

    one. This usually uses the name Set U to set distinction from the other

    sets.

    Here is an example:

    A = { 1, 2, 3, 4 }

    B = { 4, 3, 1, 2, 1 }

    C = { 4, 5, 2, 3 }Set U = { 1, 2, 3, 4, 5 }

    Null Sets

    Null Sets are sets which does not contain any element. This is

    easily identifiable because the set either has no element or has thissymbol .

    Here is an example:

    A = { }

    B = { }

    Both sets A and B are null sets.

    Relationship of Sets

    Equal Sets

    Sets are said to be Equal if and only if the sets contain exactly

    the same elements without being particular to the arrangement of the

    elements or repetition of certain elements. This relationship is shown

    through the use of symbol.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    8/69

    [8]

    Here is an example:

    A = { 1, 2, 3, 4 }

    B = { 4, 3, 1, 2, 1 }

    C = { 4, 5, 2, 3 }Set A = Set B while neither A and B is equal to C.

    Equivalent Set

    Sets are said to be Equivalent if and only if the sets contain

    equal number of elements regardless whether the elements themselvesare equal. Equivalent sets follow one-to-one correspondence. This

    relationship is shown through the use of symbol.Here is an example:

    A = { 1, 2, 3, 4 }

    B = { 4, 3, 1, 2, 1 }

    C = { 4, 5, 2, 3 }

    Set A Set C while neither A and C is equivalent to BTake note that all equal sets are equivalent but not all

    equivalent sets are necessarily equal.

    Joint Sets

    Sets are said to be Joint if and only if the sets has at least one

    common element.

    Here is an example:

    A = { 1, 2, 3, 4 }B = { 4, 3, 1, 2, 1 }

    C = { 4, 5, 2, 3 }

    Sets A, B, and C are joint sets because of theircommon elements which are 2, 3 and 4.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    9/69

    [9]

    Disjoint Sets

    Sets are said to be Disjoint if and only if the sets does not have

    any element common to them.

    Here is an example:

    A = { 1, 2, 3, 4 }

    B = { 5, 6, 7, 8 }

    C = { 9, 10, 11 }

    Sets A, B, and C are disjoint sets because they do nothave any element common to the three of them.

    Subsets

    Sets are said to be a subset of a set if all the elements of a set

    are also elements of another. This relationship is denoted by the symbol

    . B A is read as B is contained in A or A contains B where B is asubset of set A.Here is an example:

    A = { 1, 2, 3, 4 }

    B = { 1, 2, 3 }

    Set B is a subset of A , B

    A.

    C = { a, b, c, d }

    D = { d, c, a, b }

    Set C is a subset of D , C D, and vice versa.In addition, sets are said to be a proper subset of a set if all the

    elements of a set are but some of the elements of another. Therefore, a

    set has greater number of elements in comparison to its subset. Thisrelationship is still denoted by the symbol .

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    10/69

    [10]

    Here is an example:

    A = { 1, 2, 3, 4 }

    B = { 1, 2 }

    Set B is a subset of a , B A.Lastly, sets are said to be a trivial subsets if a set takes into

    consideration having a null set as a subset. This relationship is still

    denoted by the symbol .Here is an example:

    A = { 1, 2, 3, 4 }

    B = { }

    Set A and Set B, B A, are said to be trivial subsets.

    Set Operations

    Union

    Union is an operation used to combine all of the elements of

    the involved sets while considering the common elements as one. This

    uses the symbol .Here is an example:

    A = { 1, 2, 3, 4 }

    B = { 3, 4, 5, 6 }C = A BSet C = { 1, 2, 3, 4, 5, 6 }.

    Intersection

    Intersection is an operation used to have only the commonelements in the involved sets. This uses the symbol .

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    11/69

    [11]

    Here is an example:

    A = { 1, 2, 3, 4 }

    B = { 3, 4, 5, 6 }

    C = A BSet C = { 3, 4 }.

    Difference

    Difference is an operation used to remove the common

    elements of the sets involved and disregarding the rest of the elements

    of the latter set. This uses the following symbols: /.Here is an example:

    A = { 1, 2, 3, 4 }

    B = { 3, 4, 5, 6 }

    C = A BD = B A

    Set C = { 1, 2 } and Set D = { 5, 6 }.

    Complement

    Complement is an operation used to remove the elements of a

    set from the universal set. This is the same as getting the difference of

    the Universal Set and the involved set. This uses the symbol .

    Here is an example:

    U = { 1, 2, 3, 4, 5, 6, 7 }

    A = { 1, 2, 4, 5, 6 }

    B = A

    Set B = { 3, 7 }

    Take note that the union of a set and its complement results tothe universal set.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    12/69

    [12]

    Set Product

    Set Product is an operation used to get all of the possible

    ordered pairs where the x coordinate are filled by the elements of the

    former set and the y coordinate is filled by the elements of the latter

    set. Because of this, this operation is also called Cartesian Productand

    Cross Product. This operation uses the symbol x.

    Here is an example:

    A = { 0, 1, 2, 3, 4 }

    B = { 5, 6, 7, 8, 9 }

    C = A x BD = B x A

    Set C = { (0,5), (0,6) (0,9), (1,5), (1,6) (4,9) } andSet D = { (5,0), (5,1) (6,0), (6,1) (9,4) }

    Take not that Set Product is generally not commutative.

    Venn-Euler Diagram

    Venn-Euler Diagram or simple Venn Diagram is a graphical

    representation of data in dealing with the relationship and operations of

    sets. It is named after Cambridge Logician John Venn. The Set U is

    represented by a rectangle while individual sets are represented by

    circles. A shade on a region inside the diagram indicates the relation or

    the operation asked.

    Here is an example:

    U = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }

    A = { 0, 1, 2, 3, 4 }

    B = { 0, 4, 5, 6, 7 }

    C = { 0, 1, 7, 8, 9 }

    What is asked:

    A B C

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    13/69

    [13]

    Explanation:

    The example asks for the common element(s) of Sets A,

    B and C. This is through the intersection operation. Therefore the

    shaded region should be the region where the three involved sets

    intersect. And if the problem would ask what elements are contained in

    the shaded region, it would be the element 0.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    14/69

    [14]

    EXAMPLES

    1, Problem:

    Create a program which computes for the average of five

    numbers which the user will input. Use an array and imposeinteger as the only data type.

    Logic:

    A user will input one number then the number will be

    stored to a variable, which in this case is an array, and then

    repeat the process until there are five values. After which,

    another variable will compute for the sum of the stored valuesfrom the array then divide it by 5. Then, the result will be

    displayed.

    Source Code:

    #include

    #include

    main(){

    int array[5];

    int ctr, ave;

    clrscr();

    ave = 0;

    for(ctr=0;ctr

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    15/69

    [15]

    Preview:

    Review:This program uses an array array[] which will contain

    five maximum values. It uses for loop to repeat the value-

    storing process. Then the variable ave retrieves the values

    stored in array[] and compute for their sum before dividing the

    sum with 5 to have the user inputs average.

    2, Problem:Create a program that will store names of clients and

    their debts. The user will be asked for every entry stored

    whether to continue adding data or not. If not, display all stored

    clients and their according debts.

    Logic:

    This program will be almost the same as the one above

    just that this will use two arrays and will not compute for

    anything. The user will first enter the name of the client which

    will be stored in the first array. Then the user will be asked to

    enter the debt that client owes. This process will be repeated

    indefinitely as long as the user chooses to continue adding a

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    16/69

    [16]

    data. After which, the stored values will be retrieved from their

    respective arrays and displayed back to the user.

    Source Code:

    #include #include

    main(){

    char client[106];

    int debt[106];

    int cont,count,ctr;

    clrscr();

    cont = 1;

    count = 0;

    while(cont != 0){

    printf("Enter the client's name: ");

    scanf("%s",client[count]);

    printf("Enter the client's debt: ");scanf("%d",&debt[count]);

    count++;

    printf("Enter another data

    (1==yes,0==no)? ");

    scanf("%d",&cont);

    }

    printf("\n");

    for(ctr=0;ctr

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    17/69

    [17]

    Preview:

    Review:

    This program stores the clients name under client[]

    array and the debts under debt[] array. I set 106 as the

    maximum limit because of no particular reason. The variable

    cont will dictate whether to continue the program or end it

    upon having a value of 0. The variable count served as the

    holder of the number of records recorded and was set as 0

    because at the start of the program, no record was in place. Iused while loop because the condition is set for a specific

    equality value and the loop must repeat unless the cont have a

    value of 0. After the while loop, the for loop will retrieve one-at-

    a-time the values from the arrays and display it. For loop was

    used because the condition applied uses an inequality

    statement. The variable ctr served as the counter variable for

    the for loop as it reaches the specified condition.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    18/69

    [18]

    ACTIVITIES

    1, Create a program using arrays which asks the user for the number of

    entries to be entered and the values for each entry. Compute for the

    average of the values stored and display the average and all repeatedentries.

    Sample Preview:

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    19/69

    [19]

    2, Create a program which will create an arithmetic sequence after

    asking the user for the start, end, and gap between the numbers of the

    sequence. Display the sequence and ask the user what number to find

    its ordinal location in the sequence. Display the ordinal location. Repeat

    the searching until the user chooses to stop. End the program with agreeting.

    Sample Preview:

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    20/69

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    21/69

    [21]

    REAL NUMBERS

    This chapter will again focus on Mathematics more for only their

    logic would contribute to Computer Programming Fundamentals andmathematical computations.

    Kinds of Real Numbers

    Rational Numbers

    Rational Numbers are real numbers that can be written in

    fraction form or as a ratio.

    Here are some examples:

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    22/69

    [22]

    Integers

    Integers are rational numbers which belong below, above or

    exactly at zero on the number line. They are classified into three:

    positive, integers above zero on the number line, negative, integers

    below zero, and zero which is neither positive nor negative integer.

    Here are some examples:

    Natural Numbers

    Natural Numbers are rational numbers starting from positive

    one, positive two and onwards. Because of this, this set is also called

    Counting Numbers.

    Here are some examples:

    Whole Numbers

    Whole Numbers are rational numbers almost the same as

    natural numbers just that this set includes zero as one of its elements.

    Here are some examples:

    Fractions

    Fractions are rational numbers whose value is either in betweentwo natural numbers or the natural numbers themselves divided by

    one. It is written as one of the following forms: ,

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    23/69

    [23]

    Here are some examples:

    Decimal Numbers

    Decimal Numbers are rational numbers almost the same as

    fractions just that this set uses the elements of whole numbers and is

    written in this form: wholenumber.wholenumber.

    Here are some examples:

    Take note that rational numbers in decimal form must never be

    non-terminating, non-repeating else the number falls under irrational

    numbers.

    Irrational Numbers

    Irrational Numbers are real numbers if written in decimal form,

    the value on the right of the decimal point is non-terminating and non-

    repeating. It may be in symbol form, numerical form or decimal form.

    Here are some examples:

    Take note that irrational numbers could never be transformed

    to fraction form else the number falls under rational numbers.

    Properties of Real Numbers

    Like everything else, Real Numbers are governed by some

    properties. In every property, a translation in symbols where the

    variables are all real numbers is presented before the examples.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    24/69

    [24]

    Take in consideration some terms used in this chapter for those

    will be defined and explained in the next chapter.

    Closure

    Closure Property states that when real numbers undergo

    arithmetic operations, the result would always be a real number.

    In symbols:

    a + b = c

    d * e = f

    Where all of them are real numbers

    Here are two examples:

    1 + 2 = 3

    5 * 5 = 25

    Where the results are real numbers

    Commutative

    Commutative Property states that changing the order while

    considering their signs will not affect equality.

    In symbols:

    a + b = b + a

    cd = dc

    Here are two examples:

    20 + 5 = 5 + 20

    4 * 2 = 2 * 4

    Associative

    Associative Property states that changing the groupings while

    taking into consideration the kinds of operation used and the signs of

    real numbers will not affect equality.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    25/69

    [25]

    In symbols:

    a + ( b + c ) = ( a + b ) + c

    ( d * e ) * f = d * ( e * f )

    Here are two examples:7 + ( 10 + 4 ) = ( 7 + 10 ) + 4

    ( 1 * 0 ) * 8 = 1 * ( 0 * 8 )

    Distributive

    Distributive Property states that when a quantity is multipliedto a grouped quantity, the quantity is then multiplied to the individual

    members of the grouped quantity which are separated by addition or

    additions inverse.

    In symbols:

    a * ( b + c ) = a * b + a * c

    d * ( e * f ) = d * e * f

    Here are two examples:

    2 * ( 5 + 3 ) = 2 * 5 + 2 * 3

    7 * ( 0 * 23 ) = 7 * 0 * 23

    Identity

    Identity Property states that when a quantity is multiplied to its

    identity element, the result would always be the quantity itself. The

    identity element of Addition is zero while of Multiplication is one.

    In symbols:

    a + 0 = a

    b * 1 = b

    Here are two examples:

    99 + 0 = 99

    41 * 1 = 41

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    26/69

    [26]

    Inverse

    Inverse Property states that when a quantity undergoes an

    arithmetic operation wherein the other quantity involved is its inverse,

    the result would be its identity element which depends on the kind of

    arithmetic operation used. It is zero in addition and one I multiplication.

    The inverse of a quantity undergoing addition is the negative of the

    quantity. The inverse of a quantity undergoing multiplication is its

    reciprocal.

    In symbols:

    a + ( -a ) = 0b * (

    ) = 1

    Here are two examples:

    3 + ( -3 ) = 0

    6 * ( ) = 1

    Reflexive

    Reflexive Property states that a quantity is always equal to

    itself. It is usual practice that after this property is used in Mathematics

    transitive property follows.

    In symbols:a = a

    Here is an example:

    20 = 20

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    27/69

    [27]

    Symmetric

    Symmetric Property states that interchanging the left side and

    the right side of an equation does not affect its equality. This is usually

    used if, in an equality where both side is of only one quantity, the

    variable is located on the right side and its constant is on the left side of

    the equality.

    In symbols:

    a = b

    b = aHere is an example:

    3 = x

    x = 3

    Transitive

    Transitive Property states that if quantity A is equal to quantity

    B and quantity B is equal to quantity C, then quantity A is equal to

    quantity C.

    In symbols:

    If a = b

    And b = c

    a = cHere is an example:

    If d = 9

    And 9 = e

    a = e

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    28/69

    [28]

    Substitution

    Substitution states that if there exists an equation and a

    quantity involved in the said equation is equal to another quantity, then

    replacing the former quantity in the said equation with the latter

    quantity will not affect equality.

    In symbols:

    If a + b = c

    And a = d

    d + b = cHere is an example:

    If a + 9 = 20

    And a = 11

    11 + 9 = 20

    Addition

    Addition Property states that in an equation, adding a quantity

    to both sides will not affect equality.

    In symbols:

    If a + b = c + d

    Then e + ( a + b ) = e + ( c + d )

    Here is an example:

    If f + 11 = g + 9

    Then h + ( f + 11 ) = h + ( g + 9 )

    Take note that a method called transposition is just an addition

    property shortcut wherein a quantity is removed from one side of the

    equation then the inverse of the quantity is added to the other side ofthe said equation. Also take note that subtraction is only an inverse of

    the addition process thus subtraction itself is addition of a negative

    value.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    29/69

    [29]

    Multiplication

    Multiplication Property states that in an equation, multiplying a

    quantity to both sides will not affect equality.

    In symbols:

    If a + b = c + d

    Then e * ( a + b ) = e * ( c + d )

    Here is an example:

    If f + 7 = g + 3

    Then h * ( f + 7 ) = h * ( g + 3 )

    Take note that division is only the inverse of multiplication.

    Thus, dividing a quantity by a number is simply multiplying the inverse

    of the number to the said quantity.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    30/69

    [30]

    EXAMPLES

    1, Problem:

    Create a program that will reverse the values of two

    variables. Display the former and new value of the twovariables.

    Logic:

    Two variables will store the entered data by the user

    respectively. A third variable, acting as a temporary data holder

    or variable, will equate to one of the two variables. The one

    chosen between the two variables will equate to the not chosenvariable. The not chosen variable will then equate to the third

    variable.

    Source Code:

    #include

    #include

    main(){

    char var1, var2, var3;

    clrscr();

    printf("Enter data1: ");

    scanf("%s",var1);

    printf("Enter data2: ");scanf("%s",var2);

    printf("\nBefore:\n");

    printf("\tdata1: %s\n",var1);

    printf("\tdata2: %s\n",var2);

    var3=var1;

    var1=var2;

    var2=var3;

    printf("After:\n");

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    31/69

    [31]

    printf("\tdata1: %s\n",var1);

    printf("\tdata2: %s\n",var2);

    getch();

    }

    Preview:

    Review:

    The program uses a simple logic in comparison to the

    Real Numbers especially its properties. The logic itself explained the

    code used.

    2, Problem:

    Create a program which will compute for the depart

    value, arrive value, and days of recovery basing from the users

    entered values which are the hours traveled, time zones

    crossed, departure time and arrival time. Consider the following

    information:

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    32/69

    [32]

    >>Depart value = {

    0, if departure time is between 8am and 12pm.

    1, if departure time is between 12pm and 6pm.

    3, if departure time is between 6pm and 10pm.4, if departure time is between 10pm and 1am.

    5, if departure time is between 1am and 8am.

    }

    >>Arrive value = {

    4, if departure time is between 8am and 12pm.

    2, if departure time is between 12pm and 6pm.

    0, if departure time is between 6pm and 10pm.

    1, if departure time is between 10pm and 1am.

    3, if departure time is between 1am and 8am.

    }

    >>Days of recovery =

    ( hours_traveled / 2 + ( zones_crossed 3 ) +depart_value + arrive_value ) / 10

    >>All of the time should follow the 24-hour format.

    This problem was taken from OLFU 2011 CSIT Week Computer

    Programming Tournament Difficult Round hence do I not claim this as

    mine.

    Logic:

    This problem will just need conditionals to get the

    depart and arrive values and a simple computation for the days

    of recovery.

    Source Code:

    #include

    #include

    main(){

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    33/69

    [33]

    float hours, zones, dt, at, depart, arrive, dor;

    clrscr();

    printf("Enter hours traveled: ");

    scanf("%f",&hours);printf("Enter time zones crossed: ");

    scanf("%f",&zones);

    printf("Enter departure time: ");

    scanf("%f",&dt);

    printf("Enter arrival time: ");

    scanf("%f",&at);

    if(dt>8&&dt12&&dt18&&dt22&&dt8&&at12&&at18&&at22&&at

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    34/69

    [34]

    Preview:

    Review:

    Here, we asked the user to enter the necessary

    information to compute for the days of recovery. If conditional

    was used to determine the value of depart and arrive

    individually. The computation for the days of recovery follows

    the formula given just that the variables contain the appropriate

    values for an accurate computation.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    35/69

    [35]

    ACTIVITIES

    These activities were also taken from OLFU 2011 CSIT Week

    Computer Programming Tournament Easy and Average Roundrespectively.

    1, Problem:

    Create a program which would compute for the total

    payable by the user after ordering a product. The user will enter

    the following information: product name, product price, and

    overnight delivery confirmation. Let the product price be incentavos. Shipping charge is 2 pesos for items worth 10 pesos

    below and 3 pesos for the rest. An additional 5 pesos will be

    charged of the user agreed for an overnight delivery. Have the

    user apply necessary spaces.

    Sample Preview:

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    36/69

    [36]

    2, Problem:

    Create a program which will categorize the cash amount

    the user entered as 1000, 500, 100 and 50 bills. Display the

    remaining bills. Consider and display only the least possible

    combination.

    Sample Preview:

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    37/69

    [37]

    ALGEBRAIC EXPRESSIONS

    This chapter will again focus on Mathematics more for only their

    logic would contribute to Computer Programming Fundamentals,

    mathematical computations and data manipulations.

    Polynomials

    Some Terms:

    Variables are one-character letters which is used as a

    temporary representation of an unknown in order to find a value for theunknown. This usually uses lowercase letters. And the most used

    variable of all are x and y.

    Here are some examples:

    Let a = age

    b = time

    x = interesty = principal

    Constants are the numbers itself without any variable being

    multiplied to it.

    Here are some examples:

    5, 20, 47, 90

    Terms are a number, a variable or a combination through

    multiplication of number and variables in an expression. They are

    separated in by the addition. In a term, the numbers are called

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    38/69

    [38]

    numerical coefficients and the variables are called literal coefficients.

    Similar terms, commonly known as like terms, are terms having the

    same literal coefficients.

    Here are some examples:One term: 7x

    Two terms: 9y + 3x

    Three terms: 3xy + 17a 30b

    Base is the quantity, either a constant or variable, which is

    raised to a certain degree.

    Here are some examples:

    In 59, x0, t2, 3m,

    The bases are 5, x, t and 3.

    Exponent is the quantity same as base just that this speaks of

    the degree itself.

    Here are some examples:In the examples on base,

    The exponents are 9, 0, 2 and m.

    Algebraic Expressions are a term or combination of terms such

    that there is defined or finite number of involved arithmetic operations

    like addition and multiplication. There are 4 kinds of algebraic

    expressions depending on the number of terms used. They are asfollows: monomial with one term, binomial with two terms, trinomial

    with three terms and multinomial with more than three terms.

    Here are some examples:

    x, 2, 51p, ( 2y + 5z)2, ( x2 y2 ), m-3 n

    -3

    Polynomials are an expression similar to algebraic expression

    just that this does not include a negative exponent raised to any of its

    terms, numerical coefficients, literal coefficients or constants. The

    degree of a polynomialis determined by the highest exponent one of its

    terms has.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    39/69

    [39]

    Here are some examples:

    X2 + 3x 4, a + b3, u +2t, p 6

    Operations on Polynomials

    Addition and Subtraction

    In adding polynomials, similar terms are the only ones

    to be evaluated. Grouping the similar terms might prove to be

    useful in evaluating expressions but take note that such apractice will take more time. The rest are retained as is. Order is

    not important. The usual practice is to arrange the evaluated

    expression by descending powers of a certain variable. In

    subtracting polynomials, it might be useful to change the

    subtraction symbol to addition and negate the term changed. In

    such a way, the only arithmetic operation to be performed is

    addition.

    Here are two examples:

    1, ( 4a + ( 9x + 2 ) ) + ( 3a + ( 1 + 2x ) )

    = 4a + 9x + 2 + 3a + 1 + 2x

    = ( 4a + 3a ) + ( 9x + 2x ) + ( 2 + 1 )

    = 7a + 11x + 3

    2, ( 6s + 5y ) + ( -5x - 2y + 4 )

    = 6s + 5y + (-5x) 2y + 4= 6s + ( 5y + ( -2y) ) 5x + 4

    = 6s +3y -5x + 4

    Multiplication

    Laws of Exponents:

    1, an * am = an + m

    2, ( an )m = anm

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    40/69

    [40]

    3, = a

    ( n + (-m) )

    4, ( a * b )n = an * bn

    5, ( )

    n =

    Monomial Monomial:

    In monomial to monomial occurrence, simply multiply

    the two while considering the laws of exponent and the

    properties of real numbers.

    Monomial Polynomial:

    In monomial to polynomial occurrence, use the

    distributive property of real numbers to each of the terms of

    the polynomial. Multiply them like monomial to monomialoccurrence. If there exist similar terms, apply the indicated

    operation until there exist no similar terms.

    Polynomial Polynomial:

    In polynomial to polynomial occurrence, distribute first

    the first term of the first polynomial to the terms of the otherthen the second term to the terms of the other until all of the

    terms of the first polynomial has been distributed to the terms

    of the other polynomial. Multiply them like monomial to

    monomial occurrence. And if there exist similar terms, apply the

    indicated operation until there exist no similar terms.

    Special Products

    Here are the most of the special products used in Algebra:

    01, a( b + c + d + e ) = ab + ac + ad + ae

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    41/69

    [41]

    02, ( a + b )( a b ) = a2 b

    2

    03, ( a + b)2 = a2 + 2ab + b2

    04, ( a b)2 = a2 2ab + b

    2

    05, ( a + b )( a2 ab + b2 ) = a3 + b3

    06, ( a - b )( a2 + ab + b2 ) = a3 - b3

    07, ( x + a )( x + b ) = x2

    + x ( a + b ) + ab

    08, ( ax + b )( cx + d ) = acx2 + x ( ad + bc ) + bd

    09, ( a + b + c )2 = a2 + b2 + c2 + 2ab + 2bc + 2ac

    10, ( a + b )3 = a3 + 3a2b + 3ab2 + b3

    11, ( a b )3 = a3 - 3a2b + 3ab2 - b3

    Binomial Theorem

    This theorem states that for any term (a+b) raised to a

    power n,

    ( a + b )n = ( )a

    n + ( )a

    n-1b + ( )a

    n-2b2 + + ( )b

    n

    Where () =

    Pascal Triangle

    The Pascal triangle is a triangular illustration to show

    the numerical coefficients of a binomial in expanded form if

    raised to a certain number. This does not show the powers by

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    42/69

    [42]

    which the variables are raised to. But it is thought that the

    power of a variable a is decreasing until it reached a power of 0

    while for variable b, it is increasing. Here is a part of the well-

    known Pascal Triangle.

    BINOMIAL PASCAL TRIANGLE EXPANDED FORM

    ( a + b )0 1

    1 1

    1 2 1

    1 3 3 1

    1 4 6 4 1

    1

    ( a + b )1 a + b

    ( a + b )2 a2 + 2ab + b2

    ( a + b )3 a3 + 3a2b + 3ab2 + b3

    ( a + b )4 a4 + 4a3b + 6a2b2 + 4ab3 +b4

    This sequence continues onwards. The numerical coefficient of

    a term, as seen in the diagram, is the sum of the two numerical

    coefficients above it. Let us take 4th row as an example. The second

    numerical coefficient which is 3 is the sum of 1 and 2 which are above it.

    Factoring

    Factoring is changing an expression into a product of at

    least two factors.

    Types of Factoring

    1, Common Factor it is factoring an expression by a

    quantity present to the terms of the expression.

    Here is an example:

    ab + ac = a( b + c )

    2, Inverse of Special Products it is factoring using the

    concepts of special products. It is reversing the process

    undergone when factors are expanded using special products.

    Here is an example:

    x2 y2 = ( x + y )( x y )

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    43/69

    [43]

    EXAMPLES

    1, Problem:

    Create a program which will display an equiangulartriangle of asterisks. The asterisks must start with one asterisk

    at the first row and incrementing in number by one asterisk as it

    goes to the next row. The number of rows of asterisks will be

    determined by the user.

    Logic:

    The last row of the asterisk is expected to touch the side

    of the DOS window therefore spaces are present before the first

    asterisk of each row. The first row will have n-1, where n is

    equal to the user-entered value, spaces before the asterisk. The

    next will be n-2 and so on. The 1st row will have 1 asterisk, the

    2nd with two, the 3rd with 3, and so on.

    Source Code:

    #include

    #include

    main(){

    int rows;

    int ctr, spaces, asterisk;clrscr();

    printf("Enter the number of rows to be displayed: ");

    scanf("%d",&rows);

    printf("\n");

    for(ctr=1;ctr=ctr;spaces--){

    printf(" ");

    }

    for(asterisk=1;asterisk

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    44/69

    [44]

    printf("* ");

    }

    printf("\n");

    }

    getch();

    }

    Preview:

    Review:

    The program uses four variables. The rows variable

    stores the number of rows of asterisks asked by the user. The

    ctrvariable stores the current row that the program is working

    on. The spaces stores the number of spaces left to be displayed

    for the current row the program is working on. The asterisk

    stores the current number of asterisks displayed. The ctr for

    loop works for each row. The spaces for loop works for the

    spaces and the asterisk for loop works for the asterisks to be

    displayed. And before the ctr for loop ends, a next line

    statement is displayed for the program to work on the next row.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    45/69

    [45]

    2, Problem:

    Create a program similar to the one right before this

    just that the figure to be created would be a diamond-likerhombus. Other conditions remain the same. The total number

    of rows would be the twice the value entered by the user minus

    one.

    Logic:

    The logic of this program is almost to the one before

    this with additional looping for the inverted triangle having a

    deduction of one row to the number of rows of the original

    triangle.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    46/69

    [46]

    Source Code:

    #include

    #include

    main(){

    int rows;

    int ctr, spaces, asterisk;

    clrscr();

    printf("Enter a whole number: ");

    scanf("%d",&rows);

    printf("\n");

    for(ctr=1;ctr=ctr;spaces--){

    printf(" ");

    }

    for(asterisk=1;asterisk0;ctr--){

    for(spaces=ctr;spaces

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    47/69

    [47]

    Preview:

    Review:

    The source code of this program is almost similar to the

    one before it. An additional ofctr for loop is present after the

    first one. This works on the inverted triangle. The conditions

    and initializations of the inverted triangle except for the asterisk

    for loop are somehow inverted to suite the problem. The

    asterisk for loop retained the same for the reason that theprocess of displaying the asterisks is just repeated. The reason

    why the asterisks in the 2ndasteriskfor loop decreases because

    it is dependent on the 2nd ctr for loop which was modified to

    decrease its value instead of increasing it.

    The examples seem not connected to Algebraic Expressions. They

    show how data would be manipulated during the duration of program

    execution. This is very evident. Logic contained in those examples is of

    greater importance in compared to number manipulations alone!

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    48/69

    [48]

    ACTIVITIES

    1, Create a program which would display a triangle having n rows,

    where n is the whole number entered by the user. The triangle must be

    composed of whatever the user entered as characters to be displayedwhich may contain spaces.

    Sample Preview:

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    49/69

    [49]

    2, Create a program which would display a diamond-like rhombus

    having n rows, where n is a whole number entered by the user. The

    figure must be composed of but asterisks and spaces only. The number

    of allowable rows is an odd number starting from 3. If the user entered

    an even number, deduct one to his entered value. Disallow enteredvalues lower than 3. Display on the sides the current row number of the

    row it belongs to.

    Sample Preview:

    In order to solve the activities above within this chapter, the logic

    within each problem must be well understood and algebraically

    formulated. After which, data manipulation will come. Only after then

    would these activities be solved accurately and properly.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    50/69

    [50]

    RADICALS

    This chapter will again focus on Mathematics more for the only

    application of this lesson in Computer Programming is on data

    manipulations and mathematical evaluations.

    If a variable a and another b are real numbers and n as a

    positive integer greater than 1 such that bn = a, then b is called the nth

    root of a. The nth root of a is written as in symbols. If the n is 2, it is

    referred to as square and cube for n having he value of 3.

    Here are examples:

    ( 9 )3

    = 27, 9 is the cube root 27.( 2 )5 = 64, 2 is the 5th root of 64.

    ( 11 )2 = 121, 11 is the square root of 121

    The entire expression is called a radical. The symbol isthe radical symbol. The n is called the index or the order of the radical.

    The quantity inside the radical symbol is called the radicand. The default

    index of a radical is 2 or square thus it is customary to be omitted.Radicals are said to be similar if and only if their indexes and radicands

    are equal.

    Converting a radical into an equivalent expression wherein

    there is no radical in the denominator, if written in fraction form, is

    called rationalizing the denominator.

    Laws of Radicals

    1, , if is a real number.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    51/69

    [51]

    2,

    3,

    4,

    Operations on Radicals

    Addition

    Radicals could undergo addition, or subtraction, if and

    only if they are similar radicals. They are added, or subtracted,

    by undergoing the inverse of distributive property of real

    numbers on the appropriate coefficients of the terms before

    evaluating the coefficients.

    Here is an example:

    Multiplication

    There are two ways to multiply, or divide, radicals

    depending on the indexes of the radicals.

    Similar Indexes

    To multiply, or divide, radicals of similar

    indexes, simply multiply the coefficients of the radicals

    then multiply the radicands of the radicals. Of course,

    simplify the result.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    52/69

    [52]

    Here is an example:

    Different Indexes

    To multiply, or divide, radicals of different

    indexes, convert the complying radicals such that they

    will have the same indexes. Those which could not be

    converted will be retained as is. After, apply the methodof multiplying radicals having similar indexes.

    Here is an example:

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    53/69

    [53]

    EXAMPLES

    1, Problem:

    Create a program which will solve a one term radicalexpression the user will define. Thus ask the user for the base

    and the exponent of the radical.

    Logic:

    This program is very basic such that the program will

    only substitute the values entered by the user to a defined

    expression and evaluate the expression to show the exactanswer.

    Source Code:

    #include

    #include

    #include

    main(){

    int base, exponent, answer;

    clrscr();

    answer = 0;

    printf("Enter the base: ");scanf("%d",&base);

    printf("Enter the exponent: ");

    scanf("%d",&exponent);

    answer += pow(base,exponent);

    printf("\nThe answer is %d.",answer);

    getch();

    }

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    54/69

    [54]

    Another Source Code:

    #include

    #include

    main(){

    int base, exponent, answer;

    int ctr;

    clrscr();

    printf("Enter the base: ");

    scanf("%d",&base);

    printf("Enter the exponent: ");

    scanf("%d",&exponent);

    answer = base;

    for(ctr=2;ctr

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    55/69

    [55]

    Preview:

    Review:

    Both of the source codes above will display the same

    output and undergo the same process. The first code just uses

    the math library to solve the radical. The second uses for loop

    with its variable ctr. Both will have the base multiplies

    repeatedly to itself until it satisfy the intended condition.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    56/69

    [56]

    ACTIVITY

    1, Create a program which will solve a one term radical expression

    the user will define. Thus ask the user for the coefficient, the index, and

    the radicand of the radical. Just round the final answer to the nearesthundredths.

    Sample Preview:

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    57/69

    [57]

    LINEAR, LITERAL AND WORD PROBLEMS

    This chapter will again focus on Mathematics more for the only

    application of this lesson in Computer Programming is on data

    manipulations and mathematical evaluations.

    Linear Equations and Inequalities

    An equation is a statement showing equality between two

    expressions. An inequality refers to a statement showing that one of the

    two expressions involved is higher or not equal to the other. Both followsome of the properties of real numbers. They are as follows: Reflexive

    property, Symmetric property, Transitive property, Addition property

    and Multiplication property.

    The degree of a term refers to the sum of the exponents of the

    literal coefficients or variables.

    An equation is said to be a linear equation or linear inequality if

    its terms are raised up to but the first degree.

    Here is an example:

    x 2y + z +a = b + d n

    Literal Equations

    A literalequation is a statement of equality where some if not

    all of the unknowns are represented by a letters or the variables. The

    widely used examples of literal equations are the formulas.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    58/69

    [58]

    Here is an example:

    Word Problems

    Word Problems are situational-based problems which involves

    computations to find a certain unknown. Translation refers to the

    transformation of a phrase in the word problems in order to create an

    expressions, equalities or inequalities. The equations used in word

    problems are called mathematical models.

    Kind of Word Problems

    1, Number Relation Problems are problems which

    concerns the relationships among integers, fractions,

    percentage and the like.

    2, Age RelatedProblems are problems concerning the

    number of years or age as the unknown.

    3, Work Problems are problems concerning the time

    needed to finish a job and the rate a person finishes a job. This

    may involve more than one persons involvement.

    4, Mixture Problems are problems concerning with

    solutions or mixtures, their percentage of concentration and the

    amount of materials involved.

    5, Motion Problems are problems concerning basic

    physics such as time, velocity, distance and the like.

    6, Mensuration Problems are problems concerninggeometric figures like triangles, rectangles and circles.

    7, Investment Problems are problems concerning

    income, rates, investments, principals, and the like.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    59/69

    [59]

    EXAMPLES

    1, Problem:

    Jericho owns a big house. He is going to place marbletiles as his flooring. He only knows the area of the tiles he will

    need. Before he buys the tiles, he wants to verify if the tiles he

    will buy would be enough, would be lacking or would be

    exceeding what he needs. Create a program to solve his

    problem. Note that the tiles are of the same sizes and he will

    enter the land area of his house, the number of tiles he is

    planning to buy and the area of the tiles.

    Logic:

    The program will just compute for the product of the

    area of the tiles and the total number of tiles he will buy and

    compare the product to the land area.

    Source Code:

    #include

    #include

    main(){

    float land, tile, num;

    clrscr();

    printf("Enter land area: ");

    scanf("%f",&land);

    printf("Enter tile area: ");

    scanf("%f",&tile);

    printf("Enter number of tiles: ");

    scanf("%f",&num);

    printf("\n");

    if(land==tile*num)

    printf("The tiles will be enough for the house.");

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    60/69

    [60]

    else if(land>tile*num)

    printf("You will lack tiles.");

    else

    printf("You exceeded the needed number of

    tiles you\'ll need.");

    getch();

    }

    Preview:

    Review:

    The program looks and works in basic structure. No

    much reviewing is needed. Just that the program records the values

    entered by the user and compares the product concerning the tiles with

    the land area and display appropriate terms.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    61/69

    [61]

    2, Problem:

    Jericho is now problematic because he could not

    anymore think how large and how many tiles he will need for

    his floor house. Create a program to solve his problem. Notethat the program would be suggesting how much is still needed

    and also will be suggesting the area of tiles are appropriate if his

    entered area is either would exceed or lack the number he will

    be needing.

    Logic:

    This program will just be the same like the one before

    this just that the program will compute for the lacking or excess

    tiles and if needed would compute for the appropriate tile area

    and how many he will need.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    62/69

    [62]

    Source Code:

    #include

    #include

    float approp(float x, float y){

    float exact;

    exact=x/y;

    return exact;

    }

    void main(){

    float land, tile, num;

    clrscr();

    printf("Enter land area: ");

    scanf("%f",&land);

    printf("Enter tile area: ");

    scanf("%f",&tile);

    printf("Enter number of tiles: ");scanf("%f",&num);

    printf("\n");

    if(land==tile*num){

    printf("The tiles will be enough for the

    house.");

    }else if(land>tile*num){printf("You will lack %.0f tiles.",land-tile*num);

    printf("\nWhy not buy %.0f tiles with an area

    of %.0f.",num,approp(land,num));

    }

    else{

    printf("You exceed %.0f tiles.",tile*num-land);

    printf("\nWhy not buy %.0f tiles with an area

    of %.0f.",num,approp(land,num));

    }

    getch();

    }

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    63/69

    [63]

    Preview:

    Review:

    The program uses another function named approp

    which would compute for the suggested tile area depending on

    the land area and the number of tiles the user plans to buy. Theother things are just the same with the program before this. An

    additional line which would display the computed suggested tile

    area if the land area is lesser or higher to the product of the tile

    area the user entered and the number of tiles.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    64/69

    [64]

    ACTIVITIES

    1, A student from Pinalpal Elementary is academically

    challenges when speaking of Mathematics. He does not know

    how to properly solve a simple equation.

    Create a program that will help him compute for the

    value ofx. Just provide him a formula to base with and ask for

    the needed values or numerical coefficients and constants.

    Sample Preview:

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    65/69

    [65]

    QUADRATIC EQUATIONS AND INEQUALITIES

    This chapter will again focus on Mathematics more for the only

    application of this lesson in Computer Programming is on data

    manipulations and mathematical evaluations.

    A Quadratic Equation is an equation having a variable to the 2nd

    degree at most. ax2 + bx + c = 0 is the so-called standard form of a

    quadratic equation. Quadratic Inequality, on the other hand, shows

    inequality between the left side and the right side of the inequality.

    The roots of a quadratic equation are the solutions or values ofa variable making the equation valid and true. Solving a quadratic

    equation means solving for the value of the unknown.

    Laws of Quadric Equations

    1, Zero Product Property If the product of two quantities is

    zero, then at least one of them is zero.

    Here are some examples:

    1, xy = 0;

    2, ( x -2 ) ( y + 9 ) = 0

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    66/69

    [66]

    2, Square Root Property A number of the 2nd degree always

    has two square roots. Either both are positive, both are negative or

    one is negative while the other is positive.

    Here are some examples:1, ( )( )

    ( )( ) ( )( )

    2, ( )( ) ( )( )

    ( )( )

    Quadratic Formula

    This is a formula derived from the standard form of a quadratic

    equation which solves the roots of the said equation directly. Here is the

    formula:

    The only step left to do is to substitute the coefficients of the

    variables written in the standard form as replacement to the

    corresponding variable in the formula.

    Here is an example:Given the equation, 9x2 + 25x + 49 = 0, solve for x.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    67/69

    [67]

    EXERCISE

    1, Problem:

    You got tired of manually computing for the roots of x ina provided quadratic equation. Since you are a programmer,

    you thought of an idea.

    Create a program which will let you enter the values of

    a, b and c. Afterwards, the program will compute for the roots

    of x.

    Logic:

    The program will just be simple as it seems. Though the

    values ofxmay not be very accurate

    Source Code:

    #include

    #include

    #include

    main(){

    float a, b, c, x1, x2;

    float radical;

    clrscr();

    printf("Enter a: ");

    scanf("%f",&a);

    printf("Enter b: ");

    scanf("%f",&b);

    printf("Enter c: ");

    scanf("%f",&c);

    radical = pow((b*b)-(4*a*c),.5);

    x1 = (radical-b) / (2 * a);

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    68/69

    [68]

    x2 = (radical+b) / (2 * a);

    printf("\nx1 = %f",x1);

    printf("\nx2 = %f",x2);

    getch();

    }

    Preview:

    Review:

    The program simply computes for the values of x

    through the quadratic formula in linear form. And because

    there are two expected answers, both of them were shown

    whether or not they are equal.

  • 7/31/2019 Logic of Mathematics (College Algebra for Computer Science)

    69/69

    ACTIVITIES

    1, Another student hates Physics. For all she cares, shell

    choose Music over Science! But hey, you have a crush on her.

    And you surely would like to help her.

    Create a program which would solve the given formula

    in Physics. Let the user enter whatever information regarding

    the formula and supply you with the values. You have to

    identify what quantity is unknown and solve for it.

    The Formula:

    Sample Preview: