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 <iostream>
#include <algorithm>
#include <cmath>

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 << "This program will give you the lowest number and the sum of squares of the three numbers asked." << endl;
 cout << "First: ";
 cin >> no1;
 cout <<"Second: ";
 cin >> no2;
 cout << "Third: ";
 cin >> no3;

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

int sumSqueres (x,y,z) // Quiz Week 04

--Originally published at Alvaro_246

Quiz04

En el Quiz de la semana #04 tuvimos un problema el cual consistía en ingresar 3 números (x,y,z) y el programa debe de imprimir el mas grande entre esos 3 números, pero esto haciéndolo como función “minimunThree (int a, int b, int c)” y en la segunda parte del quiz teníamos que elevar cada uno de estos 3 números al cuadrado y después sumar cada resultado, para esto coloque la siguiente formula “(x*x + y*y + z*z)=” dentro de la función sumSqueres(x,y,z)

2017-02-08

#include <iostream>
using namespace std;

int minimunThree(int a, int b, int c) {
if(a>=b && a>=c){
return a;}
else if (b<=a && a<=b){
return b;}
else if (c<=a && c<=b){
return c;}
}

int sumSqueres(int x, int y, int z)
{
int R;
R= (x*x+y*y+z*z);
return R;
}

int main ()
{
float x,y,z;
cout << “Este programa encuentra el numero mas grande entre x,y,z” << endl;
cout << “Inserte el valor de x” << endl;
cin >> x;
cout << “Inserte el valor de Y” << endl;
cin >> y;
cout << “Inserte el valor de Z” << endl;
cin >> z;

cout<<“El numero mayor encontrado es: “<< minimunThree(x,y,z)<< endl;
cout<<“La suma de los cuadrados de los 3 numeros es: ” <<sumSqueres(x,y,z)<< endl;
return 0;
}
//Alvaro_246


Quiz 04

--Originally published at Ken&#039;s Disciple 01

Picture by Stokpic Stokpic

Hello everyone, on this week we had to do our Quiz 04, which was about minimum and squares. We had to ask a user to give us three numbers and we would give them the minimum of those three numbers and the sum of the squares of the numbers. We also had to do this program with the functions minimumThree and sumSquares.

Note: I’m actually learning how to give format to my program, soon I’ll be doing it easier to read and also I’ll be adding comments.

Everything in this program is the same, the only thing to highlight here is that we have to make sure that our functions return what we want them to return. In minimumThree I told the program to return the minimum of the numbers, which I did with the function min: this function returns the minimum of two numbers thats why I have  return min(x,min(y,z)); (returns the minimum of two numbers and then returns the minimum of that number plus the third one). In sumSquares its easy cause you ask the program exactly the operation you want it to do, simply as: return ((x*x)+(y*y)+(z*z));

Here are some pictures of the program, a blog of “Programming the city” that helped me, and my program as always on GitHub.

Captura de pantalla 2017-02-03 a la(s) 11.09.49.png

Captura de pantalla 2017-02-03 a la(s) 11.10.06.png

Captura de pantalla 2017-02-03 a la(s) 11.10.18.png

 

L.out


X<Y and X*X (Minimum and Squares)

--Originally published at Loading…

Today we had our 4th quiz, actually the semester is going very fast 🙄. Ken said:

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

At the begging I was very lost cause I didn’t know how to make that, so I start looking what my other classmate did, and honestly it confused my a little cause everyone had something different, only one post really help me, but then Ken explained what is the function and how it’s supposed to work and then the knowledge finally comes to my.

So I make the function of minimumThree with a if/else if/else for give the smallest value. And the sumSquares I did by multiplying the variables by its self (like the title). The rest is pretty easy, you just write what you want the program “said”. This is my code:

quiz4

 Its very importan that in the function you establish what value does it supposed to return.

quiz4-1


Quiz#4

--Originally published at OlafGC / Class #TC1017

So today we did our fourth quiz, which consists on doing two functions, so there it goes. If you need help, there’s my twitter.

Code:

#include <iostream>
using namespace std;

int minimunThree(int x, int y, int z)
{
if (x<=y && x<=z)
{
return x;
}
else if (y<=x && y<=z)
{
return y;
}
else if (z<=x && z<=y)
{
return z;
}
}

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

int main ()
{
int a, b, c;
cout<<“This program will tell you which number is the smallest out of three, and the sum of its square.”<<endl;
cout<<endl;
cout<<“Please insert the first number:”<<endl;
cin>>a;
cout<<“Please insert the second number:”<<endl;
cin>>b;
cout<<“Please insert the third number:”<<endl;
cin>>c;

int min= minimunThree(a,b,c);
int sum= sumSquares(a,b,c);

cout<<“The smallest number is: “<<min<<“.”<<endl;
cout<<“The sum of the square of those three numbers is: “<<sum<<“.”<<endl;
return 0;
} //Enrique Olaf García Cambero

quiz04


Quiz Week 4

--Originally published at how not to program

This program asks for three numbers and prints the minimum and the sum of their squares.

 

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

 

#include <iostream>
#include <cmath>
using namespace std;
int x,y,z,sumacuadrados,minimo;

int minimumThree (){

if (x<y||x<z) {
minimo= x;
}
else {
if (y<x || y<z ){
minimo =y ;
}
else {
minimo = z;
}
}

return minimo;
}

int sumSquares(){

sumacuadrados =pow(x,2)+pow(y,2)+pow(z,2);
return sumacuadrados;
}

int main (){
cout << “Type in any number” << endl;
cin >> x;
cout << “Type in any number” << endl;
cin >> y;
cout << “Type in any number” << endl;
cin >> z;

minimumThree();
sumSquares();

cout << “The minimum number is” << minimo <<endl;
cout << “The square sum is “<< sumacuadrados<< endl;
return 0;
}


Quiz 04

--Originally published at The Talking Chalk

#include <iostream>

using namespace std;

int minimumThree(int x, int y, int z)
{
if (x<=y && x<=z )
{
return x;
}
else if (y<=x && y<=z )
{
return y;
}
else if (z<=y && z<=x)
{
return z;
}

else
{
return x;
}
}

int sumSquares(int x, int y, int z)
{
return (x*x + y*y + z*z);
}
int main()
{
int a = 0;
int b = 0;
int c = 0;
cout<<“Please give me three integer numbers”<<endl;
cout<<“Your first number…”<<endl;
cin>>a;
cout<<“Your second number…”<<endl;
cin>>b;
cout<<“Your third number…”<<endl;
cin>>c;

int minThree= minimumThree(a, b, c);
int Square = sumSquares(a, b, c);

cout<<“Smallest number: “<<minThree<<endl;
cout<<“Sum of squares: “<<Square<<endl;

return 0;
}

quiz4


Quiz #4

--Originally published at Programming 101

Today we had our fourth quiz and I found it quite hard. I thought about the problem and understood it but I had a bit of trouble writing it. In the end, a friend in class helped me and I got a better idea of what to do.

Functions were a bit of a headache for me but I’ll read more pages of the book and keep on working with my friends.

Here’s a screenshot of the program and three examples to show how it works.

Cheers!

captura-de-pantalla-12


Quiz 04

--Originally published at Programming the city

In this quiz, I was very confused because of the functions we had to use, but anyways, with the help of the teacher and my classmates, I could finally do it.

The code…


#include <iostream>
using namespace std;

int minimumThree(int x, int y, int z)
{
int num;
num=min(x,min(y,z));
}
int sumSquares(int x, int y, int z){
int sumsqr;
sumsqr=(x*x)+(y*y)+(z*z);
}

int main ()
{
int x,y,z,num, sumsqr;

cout<<“Give me three numbers, I’ll show you the minimum of the three and also the sum of the squares”<<endl;
cin>>x;
cin>>y;
cin>>z;

num=minimumThree(x,y,z);
sumsqr=sumSquares(x,y,z);

cout<<“The minimum number is: “<<num<<“, and the sum of the squares is: “<<sumsqr;

}


 

And the result is….

quiz04

#TC1017

#Quiz04