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

 


Quiz 6

--Originally published at Tec Life

In order to do this quiz I search the information in one site: http://www.cplusplus.com/reference/

We have to solve 5 problems; the first one was about correcting one program and run it, so I use two new libraries in order to solve the program and start testing and rewriting the program, and the final result was this:captura-de-pantalla-2017-02-13-a-las-09-08-45captura-de-pantalla-2017-02-13-a-las-09-09-01

The second problem was about writing a program to read in a character, an integer, and a float, and print out the values, then cast to other types; so that the interaction with the user is something like the following:

captura-de-pantalla-2017-02-22-a-las-21-25-57

captura-de-pantalla-2017-02-22-a-las-21-26-06

The next program was only about to the following pattern:

                        C
                      i   I
                    s       s
                  b           b
                e               e
              s                   s
            t s e b s i C i s b e s t

 

So the only thing that I have to do was print the letters in that order and that was allcaptura-de-pantalla-2017-02-13-a-las-09-42-22

For the fourth problem they ask us to write a program to read three ints and to print them in ascending order, so the most easy thing to do was using a lot of if and else to solve this problem:captura-de-pantalla-2017-02-22-a-las-21-31-32

captura-de-pantalla-2017-02-22-a-las-21-31-43

And the last problem they ask us to write a program given the following rules, write a program to read a year (4 digit integer) and tell whether the given year is/was a leap year.

  1. There were no leap years before 1752.
  2. If the year divides by 400 then it is a leap year.
  3. All other years that divide by 100 are not leap years.
  4. All other years that divide by four are leap years.

So I use the main if as 1752 because if that wasn’t true then the year will be normal, the I use another if to say the conditions when the year will be

captura-de-pantalla-2017-02-23-a-las-08-29-54
captura-de-pantalla-2017-02-23-a-las-08-30-04
Continue reading "Quiz 6"

Quiz 4

--Originally published at Tec Life

For this quiz we have to do this:

For this quiz I want you to (in class) create a program with two functions:

  • int minimumThree(int x, int y, int z){ }  // returns the value that is smallest of x, y and z
  • int sumSquares(int x, int y, int z) {}  // returns the value of the sum of squares of x, y, z

You should make a main routine that asks the user for three numbers and then calls your functions to which should *RETURN* the value and you print in the main program.

So I started writing my program normally, declaring my variables, naming my functions and to make the user to write the three numbers.

captura-de-pantalla-2017-02-02-a-las-09-28-40

Then I make what my functions would do, that says in the first function that I am going to multiplied my variables with the function “pow” and in a parenthesis my variable “,” and the number I want to multiplied my variable, in this case 2 for square and the sum the operations.

And on my second function I put conditions with if and else to make the program know what number is bigger than the other and finally printed on the result.

captura-de-pantalla-2017-02-02-a-las-09-28-52Image from: http://www.quizfactor.com/quiz/general-knowledge/5

#Quiz04


Sum of Numbers

--Originally published at Tec Life

This was the problem:

Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.

I start declaring normally my variables as integers and one different that I give him a value “suma= 0” later I will explain that, and one variable as character “con”.

I start my main asking the user t put the ranges of the sum and then I put and if in case if the range one was lower than the range two.

Then I put a loop with a loop while that says that the result is going to be equal to the result plus one while range one be lower than range two and every time that the operations happens range one is going to be one number more that it was until be the same as range two, and finally put the result of the sum.

captura-de-pantalla-2017-01-23-a-las-09-09-43

#WSQ04

Image from: http://www.clipartbro.com/categories/greek-symbol-for-sum-clipart


Pick a Number

--Originally published at Tec Life

This was the problem:

Write a program that picks a random integer in the range of 1 to 100.

There are different ways to make that happen, you choose which one works best for you.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

I start adding the libraries that I search on internet “stdlib.h” and “time.h” to make the program to generate one random number, then I declare my variables as local variables because there are going to change and I start coding the thing that I need to make the program give me a random number, that says that is going to generate one random number between 1 and 100.

Then I make a loop in case if I don’t guess the random number that the program makes, and I put if the number I put randomly in order to guess the other number was less that it was the program is going to say me that the number insert was to low, and one in case it would be to high.

And if I guess it the program is going to say me congratulations :).

captura-de-pantalla-2017-01-23-a-las-09-31-34

#WSQ03


Temperature

--Originally published at Tec Life

This was the problem:

Write a program that will prompt the user for a temperature in Fahrenheit and then convert it to Celsius. You may recall that the formula is C = 5 ∗ (F − 32)/9.

Modify the program to state whether or not water would boil at the temperature given.

So I start coding normally “Declaring variables, including libraries, and in the main put the text that I will need in the problem”.

After asking the user the Fahrenheit degrees, I give value to the celsius degrees with this formula: C = 5 ∗ (F − 32)/9, and that was all in order to convert Fahrenheit to celsius, then I put my condition  in case if the result is bigger than 100. I start my condition with an “If” and next to it the conditions and I put what would happen, and then I put and else in case that this condition were not true.

captura-de-pantalla-2017-01-23-a-las-08-39-12

 

#WSQ02

Image from: http://climateresources.net


Codes

--Originally published at Tec Life

Here I is what I do with the first 5 programs that Ken´s give us.

Here are the problems:

  • The sum of the two numbers.
  • The difference of the two numbers.
  • The product of the two numbers.
  • The integer based division of the two numbers (so no decimal point). First divided by second.
  • The remainder of integer division of the two numbers.

In order to solve this programs I search on the internet what operations or what commands I was needed to us to solve them, so I found this page: http://www.cplusplus.com/reference/iostream/

Were it says all the thing and commands that I can use with the library <iostream>, so I start coding.

The first thing that I did was declare my variables as integers “int” followed by a coma every single variable, and in all the cases I only use 3 variables “n1, n2, n3”, n1 as the first number to print on the terminal, n2 as the second number to print, and n3 as the result of the operation. So I start texting my first order that was to print the first number that I give him so I put with a “cout” the order and with “cin” to input the number. And finally to give a value to n3 I put “n3 = n1 (the operation I wanted to made +, -, *, /, %) n2”, and print the result on the screen.

Here are my programs:

Sum:

captura-de-pantalla-2017-01-16-a-las-09-05-12

Difference:

captura-de-pantalla-2017-01-16-a-las-09-07-26

Product:

captura-de-pantalla-2017-01-16-a-las-09-11-32

Division:

captura-de-pantalla-2017-01-16-a-las-09-14-59

Residue:

captura-de-pantalla-2017-01-16-a-las-09-17-54

And 1 in all:

captura-de-pantalla-2017-01-16-a-las-09-28-24


Hello World

--Originally published at Tec Life

This is going to be the second time I am going to use c++ to do programs, I know a little bit about programming and how to use the library “<iostream>” because I worked with her before, I know how to use differents types of commands with this library and I think this is going to be very interesting to learn this again.

Here is my first program called “Hello World” using the terminal on Mac and the application Atom.

captura-de-pantalla-2017-01-12-a-las-16-38-18