Posts

Showing posts from March, 2022

Argument Passing by Value or Reference

#include // To read from the standard input, we write std::cin. These names use the // scope operatro(::), which says that the compiler should look in the scop // of the left-hand operand for the name of the right-hand operand. Thus, // std::cin says that we want to use the name string from the namespace std. // Referring to library names with this notation can be cumbersome. // Fortunately, there are easier ways to use namespace members. The safest // way is a **using declaration.** // A using declaration lets us use a name from a namespace without // qualifying the name with a namespace_name::prefix. A using declaration // has the form // using namespace::name: // Once the using declaration has been made, we can access name directly: // #include // uisng std::cin; // int main() // { // int i; // cin >> i; // ok: cin is a synonym for std::cin // cout using std::string; // Passing arguments by value void reset_passed_by_value(int *ip) { *ip = 0; // ch...

Finite Geometric Series Formula

We know that: a = first term r = common ratio n = number of terms We'r going to use a notation Sn to denote the sum of first n terms as following: Sn= sum of first n terms Sn=a+ar+ar2++arn1 We want to come up with a nice clean formula for evaluating this and we're gonna use a little trick to do it. Let's just multiple negative r on both sides of equation as following: rSn=arar2arn1arn So: SnrSn=aarn Sn(1r)=a(1rn) Sn=a(1rn)1r

Quadratic Formula

Quadratic Formula: The quadratic equation is as follows: ax2+bx+c=0 The quadratic formula tells us that the solutions to this equation is  x=b±b24ac2a So let's apply it to some problem. Let's start off with something that we could have factored just to verify that it's giving us the same answer. Example 1: x2+4x21=0 a=1,b=4,c=21 x=4±4241(21)21 x=4±16+842 x=4±1002 x=4±102 x=2±5 So: x=3 or x=7 Sothe quadratic formula seems to have given us an answer for this. You can verify just by substituting back in that these do work. (x+7)(x3)=0 x+7=0 or x3=0 x=7 or x=3 Example 2:(no real solutions) 3x2+6x+10=0 a=3,b=6,c=10 x=6±62431023 x=6±361206 x=6±846 It jus gives us a square root of a negative number. It means this will have no real sol...