Quiz 03

In this Quiz I made a program to calculate de square root and cube root of a especific number, I worked with math funtions, I used the library <cmath> beacuse I need to use Math operations the funtion are “sqrt and cbrt” and one “if” because the program don’t calculate negative numbers (-x) and the program prints “Error, Don’t use negative numbers”

quiz3

This is my Code :

#include <iostream>
#include <cmath>

using namespace std;
double square_root (double x) {
double square_root = sqrt(x);
return square_root;
}
double cube_root(double x) {
double cube_root = cbrt(x);
return cube_root;
}
double x;
int main() {
cout << “This Program calculate the Square and cube root of a specific number” << endl;
cout << “Insert a number”<< endl;
cin >> x;
if (x<=0){
cout << “No negative numbers”<< endl;
}
cout <<“square root is: “<< square_root(x)<<endl;
cout <<“cube root is : ” << cube_root(x)<< endl;
return 0; // Alvaro_246
}

Advertisements