Fibonacci Number!

--Originally published at Loading…

Hi! I know that I should have posted this since Friday, but I couldn’t post it before.

This quiz was a kind of… different, at the begging I didn’t understand very well it said:

Write a function that calculates returns the “nth” Fibonacci number where we define a function over the Fibonacci numbers mapping the naturals (starting with zero) to the Fibonacci series. So fibonacci(0) returns 0, fibonacci(1) returns 1, fibonacci(2) returns 1 and so on. Note that we are using the modern definition where the sequence starts with zero.

I know the Fibonacci series since the elementary school and I think it is absolutely AMAZING! But I didn’t know there was a formula to calculate any number in the series and that was the interesting part about this quiz, Ken gave us a very clearly explanation about it.

This is my code:

fibonacci01fibonacci02

While I was searching about the Fibonacci number and how my others classmates did this quiz, I found this page and I copied and pasted it one of the codes to print the series int he program, I know it’s wrong but it gave me a little laziness to do it by myself. It easier made the program with a function. At the begging I don’t understand how I supposed to count the numbers in the series but then Ken explained me that I have to star with the 0 like 0, 1, 2, 3… and this is how it works:

fibonacci03

P.S: It supposed that between the 0 and the 1 there should be a space.


#WSQ07 Lists 03/03/17 and WSQ07.cpp

--Originally published at Solving Problems with Programming

PICTURE OF ACTOR

So in this eight week class I started with doing the survey of mid semester where I gave ideas in order to improve this course and this and this WSQ07. I started reviewing in creating and calling functions in C++. #Mastery06, #Mastery07, #Mastery16 Use of recursion for repetitive algorithms, #Mastery17 When to use what type of repetition in a program and #Mastery18 Creation and use of Arrays/ Vectors in C++.

What I did for this numeric program is solving the problem to the user by writing a program that asks the user for 10 numbers  (floating point). Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers.Futhermore, Once you have this working, change it so that users keep giving you values until they signal “no more values”. How would you implement this and in particular for the C++ group, how to you deal with an unknown size to your array during compilation?

The quantity of the value depends of the quantity of the type float variable that has only 32 bits of leght, therefore you need a new library in order to increase the value of numbers called Biginteger.hh but I am going to add it in the next WSQ08 called Yo soy 196. Next, to deal with an unknown size of my array during compilation we need to ask the user the number of that size and save it in a variable n.

The resources I need it to solve this program are here:

ken bauer

Similar code made by Eduardo Torres

C Programming Tutorial: Functions (Call By Value, Reference,passing Arrays to function)

The following photograph shows the solution to this problem:

wsq7v2

wsq7v3

wsq7v4wsq7v5

wsq7v6

Picture of author

So at first I wrote the same structure of the program just did the same as

s1
s2
s3
s4
s5
Continue reading "#WSQ07 Lists 03/03/17 and WSQ07.cpp"

FactorialCalculator???

--Originally published at Tec Life

Well, I do no what is a factorial…. ?

So in order to solve this problem I search on the most trusthly page on internet… Wikipedia, then I notice that a factorial is :

In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,

5!=5×4×3×2×1=120. 5!=5\times 4\times 3\times 2\times 1=120.\

So the problem was this:

Create a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial).

After showing them the answer, ask them if they would like to try another number (with a simple y/n response) and either ask again (for y) or quit the program and wish them a nice day (if they answered n).

And then to solve this problem I put my normal main and later I do my function that says that is going to start in 1 because cero isn’t important, so while c is less than 1 is going to sum 1 till reach that number that the user input, and then is going to return me the new value that is going to be a or the result :).

captura-de-pantalla-2017-02-27-a-las-11-12-10

vLYLQ.gif

 

Image from: http://weknowmemes.com/2012/07/fuck-you-science/http://giphy.com/gifs/math-zach-galifianakis-the-hangover-5yLgoczEvFoE5LyoiZO


Functions??? Againnnnn???

--Originally published at Tec Life

Wellllll…. Again pffff.

The problem was this:

You will go back and do WSQ01 – Fun with Numbers again.

But this time, write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.

You main program needs to ask the user for the input and then call each function to calculate the answer for each of the parts.

So I use my older program and I start work in there, the only different thing that I do is that in this program I am going to use functions.

So I do thissssss, I give name to my function, then I put the values as int that are going to be on my functions, then I give value to my function and then return my function and the other functions was easy tooooo, the only thing that I do was change the operation of my function for what I suppose to need. And I do everything in one program why not?

Like this:captura-de-pantalla-2017-02-27-a-las-11-07-59

Image from: http://mathematicaled107.blogspot.mx

 


Fibonacci

--Originally published at Tec Life

So the problem was make to a program to do a fibonacci serie, so in order to do it I search on internet what a fibonacci serie is, and I found that is a serie that sum the two last number and converted in a new one like 2 + 3 = 5 then the next number will be 5 + 3 = 8 and like that until ends, so in order to not crash my computer I put in the main that the user write how many digits the serie would have :).

I made two programs that does the same thing, the only deference is that one uses functions and the other not.

In the program with the function I start writing my function starting on 0 that in case that the user type 0 or 1 is going to return me that number, and in case that the condition doesn’t be true then is going to return me the number – 2 + the number -1 making a serie, but that only is going to one time, so I use a do while to print all the values of the serie, then I use a for to make all the serie appears and thats all :).

And in the other program because the first to number there are not going to repeat I printed first with a cout and then I use my for to start and finish the serie depending the conditions.

And here is and image of jumping corgi in the snow :).

funnocaptura-de-pantalla-2017-03-02-a-las-09-02-46

Have fun

Image from: http://www.artifexbalear.org/img/fibonac8g.jpg and  http://buzzsharer.com/wp-content/uploads/2015/06/jumping-corgi-winter.jpg

 


On to functions!

--Originally published at my programming blog

What we needed to do in this assignment was to use the first program we did and make functions ( like the addition, difference, division, etc.).

This assignment was easy because I only needed to do simple functions.

  1. So the first thing I did was to make my functions, I named them Sum, Difference, Product, Division and Remainder.
  2. Then in the parameters I included the integers a and b.
  3. And in the return value I put (a+b), (a-b), (a*b), (a/b) and (a%b).
  4. Then I made the int main
  5. Then I asked the user for two integers and then I printed the results of each function.

Here is my code:

#include <iostream>
using namespace std;

int Sum(int a, int b){return (a+b);}
int Difference(int a, int b){return (a-b);}
int Product(int a, int b){ return (a*b);}
int Division(int a, int b){return (a/b);}
int Remainder(int a, int b){return (a%b);}

int main()
{
int a, b;
cout<<“Please enter two integers:”<<endl;
cin>>a>>b;
cout<<“The sum of these integers is: “<<Sum(a,b)<<endl;
cout<<“The difference between the integers is: “<<Difference(a,b)<<endl;
cout<<“The product of the integers is: “<<Product(a,b)<<endl;
cout<<“The division of the integers is: “<<Division(a,b)<<endl;
cout<<“The remainder of the division of the integers is: “<<Remainder(a,b)<<endl;
return 0;
}

screen-shot-2017-02-16-at-8-52-15-am

When I run it, it gives something like this:

screen-shot-2017-02-16-at-8-53-03-am

Thanks for reading! I hope it helps


Quiz 04

--Originally published at prgrm.co

In this week’s quiz, the goal was to ask the user for three different numbers and then make two functions. The first function was to display the lowest of the three numbers, and the second one was to add the squares of the three numbers.

In order to accomplish this, I needed to include three different libraries.

  • iostream
  • cmath
  • algorithm

Then the making of the functions, the first one which is to find the lowest number looks like this:

int min3(int x, int y, int z){
 return min(min(x, y), z);
 }

Notice the way the “return min(min(x , y), z)” is written, this is due the fact that the “min” function works only for two integers, so by repeating the “min” function first it chooses between “x” & “y” and then between the result from this later & “z”.

The second function is to add the squares of the three numbers, this one is relatively easier as the only thing you need to do is multiply and add, like so:

int sumofsquares(int x, int y, int z){
 return ((x*x) + (y*y) + (z*z));
 }

Here’s the full code:

#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;cmath&gt;

using namespace std;

int min3(int x, int y, int z){
 return min(min(x, y), z);
 }

int sumofsquares(int x, int y, int z){
 return ((x*x) + (y*y) + (z*z));
 }

int main(){

 int no1, no2, no3;

 cout &lt;&lt; "This program will give you the lowest number and the sum of squares of the three numbers asked." &lt;&lt; endl;
 cout &lt;&lt; "First: ";
 cin &gt;&gt; no1;
 cout &lt;&lt;"Second: ";
 cin &gt;&gt; no2;
 cout &lt;&lt; "Third: ";
 cin &gt;&gt; no3;

 cout &lt;&lt; "The smallest of the three numbers is " &lt;&lt; min3(no1, no2, no3) &lt;&lt; " ,the sum of the squares is " &lt;&lt; sumofsquares(no1, no2, no3) &lt;&lt; 
Continue reading "Quiz 04"

Post of the week #5 what things I learned in this week #5 ? And Index of Mastery Topics

--Originally published at Solving Problems with Programming

Picture of author

First let me tell you that  I learn and achieved all transversal topics and you can see it in the following link: Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03
  7. #Mastery07 Creating functions, achieved in: #Quiz03
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ?
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03
  10. #Mastery10 Use of the conditional “if”, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  11. #Mastery11 Use of “else” with a conditional if, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  12. #Mastery12 Nesting of conditional statements (ifs inside ifs): #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  13. #Mastery13 Use of
    recursion
    int-sumsquare
    double-function
    Continue reading "Post of the week #5 what things I learned in this week #5 ? And Index of Mastery Topics"

Post of the week #4 what things I learned in this week #4 ? And Index of Mastery Topics

--Originally published at Solving Problems with Programming

Picture of author

First let me tell you that  I learn and achieved all transversal topics and you can see it in the following link: Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03
  7. #Mastery07 Creating functions, achieved in: #Quiz03
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ?
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03
  10. #Mastery10 Use of the conditional “if”, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  11. #Mastery11 Use of “else” with a conditional if, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  12. #Mastery12 Nesting of conditional statements (ifs inside ifs): #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  13. #Mastery13 Use of
    recursion
    int-sumsquare
    double-function
    Continue reading "Post of the week #4 what things I learned in this week #4 ? And Index of Mastery Topics"

Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

--Originally published at Solving Problems with Programming

Picture of author

First let me tell you that in my last post i learn all transversal topics that are:

  • Ability to create C++ file and run from command line (terminal)
  • Create accounts: Blog, Twitter, GitHub
  • Submit work via Blog RSS and GitHub
  • Demonstrate use of Linux sufficient for quizzes/exams
  • Install Linux on their own computer

And you can find it in these posts:

Post of the week #2 what things i learned in this week #2 ?

Post of the week #1 what things i learned in this week #1 ?

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03
  7. #Mastery07 Creating functions, achieved in: #Quiz03
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ?
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03
  10. #Mastery10 Use of
    Continue reading "Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics"