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


WSQ01 FUN WITH NUMBERS

--Originally published at blog de Horacio

What to do:

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

  • 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

Progress:

First we name the variables so that we do not mark the program’s error, then we start to create the arithmetic operations with the variables “num1” and “num2”, and in the end we print in the screen.

captura-de-pantalla-2017-01-30-a-las-09-10-26captura-de-pantalla-2017-01-30-a-las-09-10-12

#include <iostream>
using namespace std;
int main() {
int num1,num2,suma,resta,multiplicacion,division,residuo;
std::cout << “este programa pide dos numeros y hace operaciones con ellos” << ‘\n’;
std::cout << “dame el primer numero” << ‘\n’;
std::cin >> num1;
std::cout << “dame el segundo numero” << ‘\n’;
std::cin >> num2;
suma=num1+num2;
resta=num1-num2;
multiplicacion=num1*num2;
division=num1/num2;
residuo=num1%num2;
std::cout << “la suma de los numeros es:” <<suma<< ‘\n’;
std::cout << “la resta de los numeros es:” <<resta<< ‘\n’;
std::cout << “la multiplicacion de los numeros es:” <<multiplicacion<< ‘\n’;
std::cout << “el resultado de l division es:” <<division<< ‘\n’;
std::cout << “el residuo de la division es:” <<residuo<< ‘\n’;
return 0;
};


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


Fun with numbers!

--Originally published at savhprograming

Fun with numbers

Para esta actividad necesitaremos preguntarle al usuario 2 numeros y luego imprimir lo siguiente:
  • La suma de ambos numeros
  • La resta entre ambos numeros
  • Multiplicacion entre ambos numeros
  • Divicion entre ambos numeros
  • El reciduo entre ambos numeros
 El codigo terminado es el siguiente

#include <iostream>
using namespace std;

int a, b, mult, suma, resta;
double division, resto;

int main (){
cout<<"Escribe tu primer numero"<<endl;
cin >> a;
cout <<"Escribe tu segundo numero"<<endl;
cin >> b;
suma=a+b;
resta=a-b;
mult=a*b;
division=a/b;
resto=a%b;

cout <<"Suma es igual a ="<< suma <<endl;
cout <<"Resta es igual a ="<< resta <<endl;
cout <<"Multiplicación es igual a ="<< mult <<endl;
cout <<"Sobrante es igual a = "<< resto <<endl;
cout <<"División es igual a ="<< division <<endl;
}










Primero indicamos las variables para cada operacion

int a, b, mult, suma, resta;
double division, resto;

procedemos a pedir las dos cifras

cout<<"Escribe tu primer numero"<<endl;
cin >> a; //con este codigo estamos registrando el numero tecleado como "a"
cout <<"Escribe tu segundo numero"<<endl;
cin >> b; //con este codigo estamos registrando el numero tecleado como "b"

Hacemos las operaciones  


 suma=a+b;     // suma +
resta=a-b;       // resta   -
mult=a*b;       //multiplicacion x
division=a/b;  //división  /
resto=a%b;     //residuo  %


Imprimimos

 cout <<"Suma es igual a ="<< suma <<endl;
cout <<"Resta es igual a ="<< resta <<endl;
cout <<"Multiplicación es igual a ="<< mult <<endl;
cout <<"Sobrante es igual a = "<< resto <<endl;
cout <<"División es igual a ="<< division <<endl;







Homework 1: Fun with numbers

--Originally published at Let&#039;s CODE

Our first assigment was to make a program that asked the user for two numbers and then showed the sum, difference, product, integer quotient and remainder of that numbers. The code I made is very simple, I just included an additional library (<math.h>) to use the fabs function whe dividing the numbers, because the instructions … Continue reading Homework 1: Fun with numbers

Fun With Numbers

--Originally published at how not to program

For this activity, we should ask the user for two numbers and display the following results:

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

 

captura4 captura5 captura6

 

If you want to make improvements or modifications, here is the code for you to copy and paste it anywhere.

#include <iostream>
using namespace std;

double sum, diff, prod, rem;
int div;

int main (){
int a;
cout<<“Type in one number”<<endl;
cin >> a;
int b;
cout <<“Type another number”<<endl;
cin >> b;

sum=a+b;

diff=a-b;

prod=a*b;

rem=a/b;

div=a%b;

cout <<“Sum is “<< sum <<endl;

cout <<“Difference is “<< diff <<endl;

cout <<“Product is “<< prod <<endl;

cout <<“Remainder is “<< rem <<endl;

cout <<“Division is “<< div <<endl;

return 0;
}

 


Fun with numbers!

--Originally published at TC1017

The last week I finished the first c++ program for the course (not my first one), which consisted in asking the user for two numbers and printing their sum, difference, product, division, and remainder of the division. I had c++ knowledge before starting this course, so it was a pretty easy program in my opinion. I had no help in the process of writing the program, but I asked Ken how to compile it and show it on Ubuntu . The program has 2 inputs and 5 outputs of different operations.

I´ll leave the program, and its output below: funwnumbers.jpg

funwnumbers1.jpg