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

 


Fun with numbers

--Originally published at Solving problems with programming

In this homework with 2 numbers that you ask to the user you will do multiple operations, sum, substracion, division, multiplication and residue.

First you nee to declare those variables that will get the value of those two numbers, you assign the values with cin. With the values in the variables the rest is the very easy

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int num1, num2, res;
cout <<“Escribe número 1 ” <<‘\n’ ;
cin >> num1;
cout <<“Escribe numero 2 ” <<‘\n’;
cin >> num2;
res = num1 + num2;
cout <<“Suma = “<<res<< ‘\n’;
res = num1 – num2;
cout <<“Resta = “<<res<< ‘\n’;
res = num1 * num2;
cout <<“Producto = “<<res<<‘\n’;
res = num1 / num2;
cout <<“Division = “<<res<<‘\n’;
res = num1 % num2;
cout <<“Residuo = “<<res<<‘\n’;

}


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"

WSQ 01 Fun with Numbers

--Originally published at Franco TC1017

This was the first assignment, I did it long ago but I deleted it by accident. I re-upload it to have every assignment on my blog. Now my blog has no chronological order and my OCD is worse than ever.

Anyway, the program asks the user for two numbers and then it adds, substract, multiply, divide and gives the reminder of their division.

 

#include <iostream>

int main() {

int num1;
int num2;

std::cout << “Enter first number:” << ‘\n’;
std::cin >> num1;
std::cout << “Enter second number:” << ‘\n’;
std ::cin >> num2;
std::cout << “Sum, difference, product, quotient, reminder, respectively.” << ‘\n’;

std::cout << num1 + num2 << ‘\n’;
std::cout << num1 – num2 << ‘\n’;
std::cout << num1 * num2 << ‘\n’;
std::cout << num1 / num2 << ‘\n’;
std::cout << num1 % num2 << ‘\n’;

return 0;
}

 

fun-with-numbers-codefun-with-numbers-terminal


But why!?

--Originally published at TC1017

Well, I keep asking me why I didn’t ask for help but then I realize I thought i can’t handle it #ThisIsWhyIFail. Just kidding, WSQ01 is ready…

P.S I don’t really know if I have to explain them since I think only my classmates will see the post, but If you are interested in learning how to do them, leave a comment in the post.

#BAPL

Link to the code: https://docs.google.com/document/d/10XjW9zjipcz1PNcIn5e9NwzRC9irkxIVFmWnfJbxQQg/edit?usp=sharing


WSQ01- Fun with numbers

--Originally published at Programming course

So the assignment was to ask the player/user (¿?) for two numbers, and our job was to create a program that could sum, substract,multiply, divide and give the remain of the division.

  1. First I asked for the two numbers
  2. Then I declared the variables (Using int for the two numbers, the sum and the substraction and the multiplication and using double for division and remain because they can be numbers with decimals)

And the formulas I used were:

  • sum: a=x+y
  • difference: a=x-y
  • multiplication: a=x*y
  • division: a=x/y
  • remain:x%y

And basically that’s it ?

wsq01-atom wsq01-terminal