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 << i; // error: no using declaration; we must use the full name // std::cout << i; // ok: ex

Finite Geometric Series Formula

We know that: a = first term r = common ratio n = number of terms We'r going to use a notation $S_n$ to denote the sum of first n terms as following: $S_n$= sum of first n terms $S_n=a+ar+ar^2+\cdot\cdot\cdot+ar^{n-1}$ 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: $-rS_n=-ar-ar^2-\cdot\cdot\cdot-ar^{n-1}-ar^n$ So: $S_n-rS_n=a-ar^n$ $S_n(1-r)=a(1-r^n)$ $S_n=\frac{a(1-r^n)}{1-r}$

Quadratic Formula

Quadratic Formula: The quadratic equation is as follows: $ax^2+bx+c=0$ The quadratic formula tells us that the solutions to this equation is  $x = \frac{-b\pm\sqrt{b^2-4ac}}{2a}$ 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: $x^2+4x-21=0$ $a=1, b=4, c=-21$ $x = \frac{-4\pm\sqrt{4^2-4\cdot1\cdot(-21)}}{2\cdot1}$ $x=\frac{-4\pm\sqrt{16+84}}{2}$ $x=\frac{-4\pm\sqrt{100}}{2}$ $x=\frac{-4\pm10}{2}$ $x=-2\pm5$ 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)\cdot(x-3)=0$ $x+7=0$ or $x-3=0$ $x=-7$ or $x=3$ Example 2:(no real solutions) $3x^2+6x+10=0$ $a=3, b=6, c=10$ $x=\frac{-6\pm\sqrt{6^2-4\cdot3\cdot10}}{2\cdot3}$ $x=\frac{-6\pm\sqrt{36-120}}{6}$ $x=\frac{-6\pm\sqrt{-84}}{6}$ It jus gives us a square root of a negative number. It means this will have no real sol