Quiz

Quiz 1

#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
float r, h, v;
cout<<“Dame el radio: “;
cin>>r;
cout<<“Dame la altura: “;
cin>>h;
v=3.1416*r*r*h;
cout<<“el resultado es “<<v;
getch();
return 0;
}

#include <iostream>
#include <conio.h>
#include <cstring>
using namespace std;
int main()
{
int resul2, num1, num2,resul3;
float resul1;
cout<<“Dame un numero: “;
cin>>num1;
cout<<“Dame otro numero: “;
cin>>num2;
resul3=num1*num2;
resul2=(int)num1/num2;
resul1=num1/num2;
cout <<“nEl resultado de multiplicarlos es “<<resul3;
cout <<“nTu resultado de una division entera es “<<resul2;
cout <<“nEl resultado de una division con decimales es “<<resul1;
}

#include <iostream>
#include <conio.h>
#include <cstring>
using namespace std;
int main()
{
int resul2, resul1, resul3, resul4;
float num1, num2;
cout<<“Dame un numero: “;
cin>>num1;
cout<<“Dame otro numero: “;
cin>>num2;
resul1=num1*num2;
resul2=num1/num2;
resul3=num1+num2;
resul4=num1-num2;
cout <<“nEl resultado de multiplicarlos es “<<resul1;
cout <<“nEl resultado de una division es “<<resul2;
cout <<“nEl resultado de una suma es “<<resul3;
cout <<“nEl resultado de resta es “<<resul4;
}

Quiz 2

#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int num, i;
i=1;
cout<<“nCuantos estrellas quieres: “;
cin>>num;
do
{
i++;
cout <<“*”;
} while(i<=num);
getchar();
return 0;
}

#include<iostream>
#include<math.h>
long superpower(long a,long b)
{
using namespace std;
long res;
res=pow(a,b);
cout << “El resultado de “<<a<<“^”<<b<<“=”<<res<<endl;
}
int main(){
using namespace std;
long base,exp;
cout << “Dame la base del numero a elevar”<<endl;
cin>>base;
cout << “Dame el exponente del numero a elevar”<<endl;
cin>>exp;
superpower(base,exp);
system(“pause”);
return 0;
}

Quiz 3

#include <iostream>
#include <cmath>
#include <math.h>
#include <conio.h>
#include <stdio.h>
using namespace std;
int main()
{
int x1,x2,y1,y2;
double x,y,result;
cout <<“nDame la cooordenada x de el eje x del primer punto”<<endl;
cin>>x1;
cout <<“nDame la cooordenada x de el eje y del primer punto”<<endl;
cin>>y1;
cout

Continue reading “Quiz”

Quiz #3

Hey guys!

I had my quiz #3 and I want to share it with you. I had to make two different codes and these are the instruction:

1)

Write a function called distance(x1, y1, x2, y2) which receives four numbers which represent two points in the cartesian plane. The function should return the distance between the two points (x1,y1) and (x2,y2). Remember that the square of the hypotenuse of a right angle triangle is equal to the sum of the squares of the two other sides.

Here’s my code:

2016-02-13

It is not a difficult code because we only have to use a common formula used commonly in math and physics. We have to adapt it in a way the code can get it. We need to declare 2 points in the cartesian plane that’s why we have to use 4 different variables.

NOTES:

  • Use float for non-integer numbers for more accuracy.
  • As you can see we are using another library calls <cmath> because we have to use a square root and it is represented by “sqrt()”.

2)

Write a function called fibonacci which receives a single parameter “n” (a non-negative integer) and returns the nth number in the fibonacci series which is: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89…………

So, fibonacci(0) would return 0. fibonacci(5) would return 5 fibonacci(8) would return 21.

Note that the first two fibonacci numbers are 0 and 1. All others are the sum of the previous two fibonacci numbers.

Here’s my code:

2016-02-13 (1)
2016-02-13 (2)

For definition the fibonacci number is a series of whole numbers in which each number is the sum of the two preceding numbers. Beginning with 0 and 1, the sequence of Fibonacci numbers would be 0,1,1, 2, 3, 5, 8, 13, 21, 34, etc. using the formula n =

Continue reading “Quiz #3”