Quiz 6

Cout<<“Hello People”<<endl.

Hello again, now I’m posting about my quiz 6 of the course. On this time, we have to create a program who can give the great common denominator between two numbers that the user enter into the program, here the instructions:

The function should receive two integers and return an integer.Obviously you should test your function, so create a main program that asks the user for two values, calculates the gcd and displays that.

It wasn’t too difficult, because we just need an if conditional and a while loop to make the cicle and find the greatest common denominator between the two numbers, and here, the code:

q6.png

And the program on terminal running:

g6

Don’t forget to look my codes on github so you can use it and learn how to make it, also you can add comments !!

https://github.com/eduardomrlsg/TC101/blob/master/Quiz6

Regards. EdMo.

 

QUIZ 5

42c150433839bad235f1f83925cf3875527c7bb3-vector-storefront_189303863

Hello people.

I am here to post about the quiz that I made some days ago about two programs: One which has to:

  1. Create a function called is_palindrome which receives a string as a parameter and returns true if that string is a palindrome, false otherwise. Remember that a palindrome is a word that is the same forward or backward. For full points your function must ignore case and must work with any character (not just letters). So (“Dad$dad” is a palindrome even though the D is capital and d is lower case).

On this program I learned how to use vectors and make a palindrom with it, taking the word and then taking the reverse of the word, Yeah, vectors rules.

To learn more about vectors on C:  http://www.cplusplus.com/reference/vector/vector/

Here my code:

q5

Running:

palg

And the second one:

  1. Create a function called find_threes that receives as a parameter a list (or Vector or array for C++ students) of numbers and returns the sum of all numbers in that list that are evenly divisible by 3. Note if using vectors, you will need an additional parameter to represent the number of numbers in the array. So if the list was [0,4,2,6,9,8,3,12], the function would return 30 (0+6+9+3+12)

Here, we have to use an array to get the range of numbers that we are going to use in our function “threes”. It was a little bit difficult but with the help of other students of the class I can make it.

The code:

3

And running:

g3

To more information check all my codes on github and dont forget to make questions or add comments to stay in contact with me;D

https://github.com/eduardomrlsg/TC101/blob/master/Quiz5Palindrome

https://github.com/eduardomrlsg/TC101/blob/master/Quiz5Threes

Regards, EdMo.

Quiz 6 Euclides

matemazz39

In this quiz we had to make a program that tells you the greatest common divisor between two integer numbers. So the program asks for the biggest number and then the smallest.

For this we have to use the Euclid’s Algorithm: (Wikipedia obviously)

The Euclidean algorithm is based on the principle that the greatest common divisor of two numbers does not change if the larger number is replaced by its difference with the smaller number. For example, 21 is the GCD of 252 and 105 (252 = 21 × 12 and 105 = 21 × 5), and the same number 21 is also the GCD of 105 and 147 = 252 − 105. Since this replacement reduces the larger of the two numbers, repeating this process gives successively smaller pairs of numbers until one of the two numbers reaches zero. When that occurs, the other number (the one that is not zero) is the GCD of the original two numbers.

Here is a video, it´s in Spanish but explains this quite good:

Captura de pantalla 2016-04-05 a las 10.01.02 p.m.

Captura de pantalla 2016-04-05 a las 10.01.42 p.m.

Thanks to Baruch who taught me how to make the loop.

thak you

Quiz #5-1

For this quiz first we had to do a function which will turn a word on one side to the other and tell if it was written right on both sides, i had to do research in order to do this one but anyways here it goes

Screenshot15.1

then you ask for the word, and work with the function

Screenshot15.2

and finally if you want all the code find it here: CODE

 

 

#QUIZ06 Euclidian Algorithm

One week later is way better than never, instructions of the Quiz are here.

Summing the instructions we should create a code which receives two numbers or parameters from the user, then in a function print the biggest denominator that divides both numbers.

10330240_1045265532201362_6669094908167145769_n.jpg Clic on the amazed monkey for more information about the Euclidian Algorithm

                           [CODE on cygwin]

Once you understand the logic of the problem, its pretty easy to solve, you will only need a 4 lines function + the main part of the code.

jenfjejeAs you can see you only need to link two values to the function whose are the first and second value that the user typed.

Sin knceejdf.png

Here is the proccess using the two numbers of the Ken example´s page. 270 & 192.

Its was a good challenge, to improve our knowledge, I didn´t know what a Euclidian Algorithm was so it was interesting, and I think useful.

As Always, Random Stuff at the end[+Great song]

Yall love science(or Im just guessing) and for the same reason you´ll love this video

And a lovely song, of Alt J, Enjoy! And have a great holiday!

Quiz 4 Euler Number

Hello people, I was busy for a long time but here I am. This post is about my first quiz of the second partial of the semester. It was not too difficult but I got in trouble with some parts of the code but I finally did it. Well, the instructions for the quiz were:

Create a function called euler_calc with a single parameter precision. The value of precision is used to determine when to stop calculating. Your calculation will stop when the two consecutive values estimating e differ by less than precision (remember to use absolute value when calculating the difference between two values here).

I search information on Wikipedia about the Euler number to get the idea, and I found interesting information about it: The number e is an important mathematical constant that is the base of the natural logarithm. It is approximately equal to 2.71828,[1] and is the limit of (1 + 1/n)n as n approaches infinity, an expression that arises in the study of compound interest. It can also be calculated as the sum of the infinite series.

Thanks Euler for doing our life easier and harder at the same time.

Here the code of my program.

euleeeeeereulerrrrrrrrr

The new thing here was the SET PRECISION function that I used to call to the user for the number of decimals that he wants to use.

It has to look like that:

#include <iomanip>      // std::setprecision

int main () {
  double f =3.14159;
  std::cout << std::setprecision(5) << f << 'n';
  std::cout << std::setprecision(9) << f << 'n';
  std::cout << std::fixed;
  std::cout << std::setprecision(5) << f << 'n';
  std::cout << std::setprecision(9) << f << 'n';
  return 0;
}

**Don't forget to use the iomanip library to run it without problem.

And the program running:

euruning
dancing-banana
Continue reading "Quiz 4 Euler Number"

#QUIZ05 Palindrome & 3Divisibles

Sorry for posting Quiz05 until now but i totally had my mind in the Lychrel numbers(now on my blog if you want to check it) .

tumblr_o3nm7uOO7v1tiyj7vo1_500.jpg

Quiz05, first thing to do is something related to the Lychrel, check if a word(string) its a palindrome or if its now, creating a bool function for it and printing the result.

Some new stuff on the code, like using .size and .rend, not to hard to understand them but here´s more information. There´re different ways to get the inverse of a string, the one I´ve done in the code is the easier to do in my opinion. (If you find an easier one let me know)

Palindrome:[CODE]

palin.png

As you can see we´re working with a boolean expression ´cause we only need to verify if its a palindrome or its not. Instead of doing it as a bool try using int and give a 1 if ifs a palindrome or 0 if its not, both methods work perfectly.  Quick doubt-solving page for you who don´t know what´s r.begin and .rend.

And here the main part of the code:

main.png

Just make a condition for the boolean expression and thats all.

3Divisibles:[CODE]

In this case, you have to create an array which contains a whole bunch of numbers that the user types and add only the ones which are divisibles by 3. Example: Range(5,3,10,6,2) from this range it only add the 3 and the 6. So it prints the total of the addition as a 9.

In my case, before giving the array a value, I ask the user for the numbers of values he will type, and thats the capacity of the array.

3div.png

And just like the #WSQ10 you create a for loop to ask for all the values.

total

Easy to understand, I

Sin título.png

Continue reading “#QUIZ05 Palindrome & 3Divisibles”