Fun With Numbers

This program helps us to make simple calculations by giving it two integer values. To make this program I asked a friend for some help and also I checked the c++.com page.

Here I have my program, as you see it is well done.

funwithnumbers1

I just needed to compile it and all job done.

At first I had some problems, but then everything was perfect.

fwnumbers2

It works perfectly! 🙂

 

 

Fun with numbers (wiiiii)

 

“”What to Do- WSQ03

Ask the user for two integer values, then use those two values to calculate and show the following:

  • 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. “

 

…here we GOashamed

Como primer paso, … quizá me compliqué un poco, pero anteriormente no había averiguado casi nada sobre python, mas que guardar los archivos y como imprimir , pero vaya :l aquí tenemos que usar operadores aritméticos.. y pensarle casi nada (:

.. Y digo que me compliqué porque primero lo hice en C# para ver si funcionaba bien mi algoritmo. jeee. Y funcionó 😀, ahora a traducirlo (:

1.- Cómo poner un input (mostrar un texto y que el usuario te dé una respuesta) y que se guarde la respuesta en una variable.

Aquí las dos variables que debemos de tener sólo serán los dos números los cuales se harán las operaciones. Así que:

num1 = int(input(“ingrese un numero: “)) 

eso funcionaría para ambos.

NOTA: en Python importan muuuuuuuuuuuchisimo los *espacios*, ya que, indican la secuencia en la que se seguirá lo que pongamos, introducir un condicional en otro, etc. (Aquí no importará, ya que solo son operaciones a efectuar y texto a mostrar, así que lucirá todo *pegado*)

2.- Las operaciones aritméticas a realizar son restas, multiplicaciones y división (el cociente y el residuo). En el siguiente link <-viene como representar las operaciones en python.


 

Cociente de una división. El cociente de una división se calcula con el operador //. El resultado será de tipo entero o decimal dependiendo del tipo de los números empleados (pero en caso

ashamed

Continue reading “Fun with numbers (wiiiii)”

Fun With Numbers

Este programa te pedira dos valores y de ellos va a sacar lo siguiente:
1.- La diferencia entre ellos (Resta)
2.- El producto de los dos números (multiplicación)
3.- El resultado, sin residuo, de la división.
4.- El residuo de la división.

Como siempre tenemor que tener nuestro int main e incluir nuestra libreria en la parte superior.

Captura de pantalla 2016-01-26 11.57.47.png

Tenemos que crear las variables e indicarle al programa de que tipo son, en este caso las variables son los numeros que le pediremos al usuario y seran de tipo “int”

INT

Utilizaremos la funcion “printf” para que el usuario pueda ver lo que escribimos en esa función, se escribe entre parentesis y entre comillas. la diagonal y la n que aparece al final del escrito es para dar un salto de linea.

printf

La siguiente función que necesitaremos sera la de “scanf” cuando queramos que el usuario tenga que ingresar algo. Entre comillas tienes que indicarle al programa que tipo de entrada tiene que recibir del usuario, en este caso como es un numero utilizamos “%d” y despues se tiene que escribir a variable en la cual quieres guardar dicha entrada.

Captura de pantalla 2016-01-26 12.01.35

Para terminar nuestro código tenemos que imprimir en pantalla los resultados que queremos y para ello utilizamos de nuevo la funcion printf pero como ahora queremos que imprima un dato que esta guardado en el programa tenemos que decirle que es un valor int con %d y despues de las comillas y de una coma, escribimos la variable o en nuestro caso la operacion que queremos que se muestre en pantalla.

Captura de pantalla 2016-01-26 12.21.55

Por último, al correr nuestro programa en Cygwin tendrá que ser como el siguiente.

Captura de pantalla 2016-01-26 12.24.05

#WSQ03

This assisgment was a little bit trickier than the previous one, but still is fairly simple. All I needed to do is to ask the user to type 2 numbers and then make 4 different operations with such numbers.

For knowing how to write this code I again read some parts of the “Think Python” book.

http://www.greenteapress.com/thinkpython/thinkpython.pdf

I had a doubt about how to do the integer division so I searched online for the answer and this web page gave me the solution.

http://stackoverflow.com/questions/183853/in-python-what-is-the-difference-between-and-when-used-for-division

 

Here is my final code:

print (“This program will do some operations with 2 numbers you choose”)
print (“Type a number”)
num1=input ()
print (“Now type another number”)
num2=input ()
sub=int(num1) – int (num2)
multi= int(num1) * int (num2)
div= int(num1) // int (num2)
rem= int(num1) % int (num2)
print(“The difference of those numbers is”, sub)
print(“The product of those numbers is”, multi)
print(“The division of those numbers is”, div)
print(“The remainder of the division of those numbers is”, rem)

 

And this is the program:

numbers

numbers2

http://www.greenteapress.com/thinkpython/thinkpython.pdf

WSQ03 ‘Playing with numbers’

3rd week of the semester and Ken’s blog has up to 7 homeworks. That means that I am 4/7 done from right now. Ever wondered how a calculator is programmed to do one’s  work for them? You know when one is too lazy to add 5 + 3 and they use the calculator to make sure or even to do enormous operations for Physics.

At this WSQ we were in charge to make the user pick two numbers. Let “x” be the first number and “y” be the second number. So at this assignment this two numbers picked by the user are supposed to be added to each other , also  x has to be substracted by y, then x and y have to multiply each other and finally x has to be divided by y. However at this division the final result has to be an interger so you have the remainder also. That means no decimal.

My first try at the addition part, with the assistance of my partner, it was a failure since instead of the variables adding each other, they just stood beside each other like this:

sumafail

Rusty keys

#WSQ03 #WSQ1017

For this next program we were instructed to make some basic operations out of two numbers given by the user. It was completed almost with ease, and I say almost because I had to recheck some basic stuff such as the predecence of operators and some syntaxs rules when using cout and cin. This was achieved thanks to the ebook referred in the syllabus.

Below we can see both the source code and the running program:

proof_op.PNG

Source code:

#include <iostream>
using namespace std;

int firstnumber;
int secondnumber;

int main(){

cout << “Reminder: This program only accepts integer numbers” << endl;
cout << endl;
cout <<“Please enter the first number:”<< endl;
cin >> firstnumber;
cout << “Please enter the second number: “<< endl;
cin >> secondnumber;
cout << endl;

cout <<“The difference between your first number and your second number is: “;
cout << firstnumber – secondnumber << endl;
cout << endl;
cout <<“The difference between your second number and your first number is: “;
cout << secondnumber – firstnumber << endl;
cout << endl;

cout <<“The product of both numbers is: “;
cout << firstnumber*secondnumber <<endl;
cout << endl;

cout <<“The result of your first number divided by the second is: “;
cout << firstnumber/secondnumber << endl;
cout << endl;

cout <<“The remainder of the division is: “;
cout << firstnumber%secondnumber << endl;

}

———

Photo Credit: <a href=”https://www.flickr.com/photos/42333408@N02/6248243245/”>Felipe_Borges</a&gt; via <a href=”http://compfight.com”>Compfight</a&gt; <a href=”https://creativecommons.org/licenses/by-nc-nd/2.0/”>cc</a&gt;

Fun With Numbers (WSQ03)

The goal is to create a program that asks the user for two numbers and Python will show the difference between them.

First of all, we need to know the keywords that we’ll use. I write this at the beginning because I had no freaking idea about which labels would make what I wanted:

print: Print is the keyword that will order Python to write an specific sentence on the editor, so the user can understand what we want him/her to do. The syntax should be lije this example: print (“Text that you want to print”)

input: This label will keep the information that we’re asking for. The syntax will be like this: input (“What we’re asking the user to write”)

float: For this program, “float” helped me to make the difference between the inputs. I’ll show you what I’m talking about when I show you my program.

The difference of the two numbers.

Ok, now, if we want to make the difference of two numbers, we need to ask for them, but also to assign a variable to each one, so then we can make the operations.

To get that, we assign a different variable to each input, like in the image below

fwn1 - copia

To get the result, we just need to add another variable and assign it the value of the difference.

But be careful, THIS is why you need the floats.

fwn1

If you just type (+) the program will print the first number followed by the second one, but if you write “float” before each one, you’ll get thisfwn3

I figured out that a float was needed thanks to this post.

This YouTube video was helpful too.

The product of the two numbers

We keep going and make exactly the same process, but this time, instead (-), we type

fwn4
fwn5 - copia
fwn6

Continue reading “Fun With Numbers (WSQ03)”

#WSQ03

This is how i did this assignment:

#include <iostream>
using namespace std;

int a, b, r, m, d, rem;

int main(){
cout<< “Give me two integers values”<< endl;
cin>>a;
cin>>b;
r=a-b;
cout << “resta= ” << r << endl;
m=a*b;
cout << “multiplicacion= ” << m << endl;
d=a/b;
cout << “división= ” << d << endl;
rem=a%b;
cout << “residuo= ” << rem << endl;

return 0;

}

·Fun with numbers· #WSQ03

Well, another homework… haha just kidding. I’m learning how to improve my codes and all that stuff. I started reading some articles and looking for examples in c++, as I said previously, I didn’t remember how to write in c++. I spent a time exploring this helpful page. There a lot of tutorials in c++ and references.

Captura de pantalla 2016-01-22 a las 12.03.43

After reading for a while some tutorials and articles, I decided to start writing my code. My objective was to create a program that given two numbers, it could calculate different operations. I looked in some of my classmate’s programs in order to remember how to write all de cout and cin stuff.

And here is the result, after a few mistakes and trying to figure it out what was wrong, my program was finally running!

Captura de pantalla 2016-01-22 a las 12.16.38

And here is my program working in Terminal…

Captura de pantalla 2016-01-22 a las 12.18.30

Also, you can see my code on GitHub here

Captura de pantalla 2016-01-22 a las 12.20.30

Alex H.

24294566811_7004231734_k
Another Sunrise over the Alps by Rogg4n Link on Flickr: https://www.flickr.com/photos/128294308@N05/24294566811/in/explore-2016-01-14/