--Originally published at My awesome Blog!
Quiz 3 :
First i added the library “cmath” so i can use the functions for square and cubic root , then i declared some variables for to use as shown.
Inside the main function i ask the user for the value of x, then i send the value of x to the function Square_root , that returns the value for the result for the square root . when it finishes it goes back to the main and then sends the value of x to the function Cubic_root and returns a value for the result.
i have an if-else to decide if the x value is negative to decide if its a imaginary root.
Enjoy!
CODE HERE:
#include <iostream>
#include <cmath>
#include <cmath>
using namespace std;
double x1,x2,x, squareroot , cubicroot ;
double x1,x2,x, squareroot , cubicroot ;
double Square_root (double x) {
squareroot = sqrt( x );
return squareroot ;
}
double Cubic_root (double x) {
return squareroot ;
}
double Cubic_root (double x) {
cubicroot = cbrt (x);
return cubicroot;
}
int main()
{
cout << “Escribe el valor de x” << endl;
cin >> x;
return cubicroot;
}
int main()
{
cout << “Escribe el valor de x” << endl;
cin >> x;
x1 = Square_root(x);
x2 = Cubic_root(x);
x2 = Cubic_root(x);
if (x >0 ) {
cout << “la raiz cuadrada de ” << x << “es ” << x1 << endl;
cout << “la raiz cubica de ” << x << “es ” << x2 << endl;
cout << “la raiz cubica de ” << x << “es ” << x2 << endl;
}
else {
else {
cout << “La raiz es imaginaria ” << endl;
}
return 0;
}
return 0;
}