Assignment 1 C++
Assignment 1 C++
Semester
Program Name
Course Name
Course Instructor
___________
Mathematical Expressions
Example:
#include <iostream>
#include <cmath>
int main() {
int x = -5;
int absoluteValue = abs(x);
std::cout << "Absolute value of " << x << " is: " << absoluteValue << std::endl;
return 0;
}
Output:
Example:#include <iostream>
#include <cmath>
int main() {
double x = 25.0;
double squareRoot = sqrt(x);
std::cout << "Square root of " << x << " is: " << squareRoot << std::endl;
return 0;
}
Output:
Example:#include <iostream>
#include <cmath>
int main() {
double x = 27.0;
double cubeRoot = cbrt(x);
std::cout << "Cube root of " << x << " is: " << cubeRoot << std::endl;
return 0;
}
Output:
4. Power: pow(x, y)
Example:#include <iostream>
#include <cmath>
int main() {
double x = 2.0;
double y = 3.0;
double result = pow(x, y);
std::cout << x << " raised to the power of " << y << " is: " << result << std::endl;
return 0;
}
Output:
5. Exponential: exp(x)
Example:#include <iostream>
#include <cmath>
int main() {
double x = 1.0;
double result = exp(x);
std::cout << "Exponential of " << x << " is: " << result << std::endl;
return 0;
}
Output:
Example:#include <iostream>
#include <cmath>
int main() {
double x = 10.0;
double naturalLog = log(x);
std::cout << "Natural logarithm of " << x << " is: " << naturalLog << std::endl;
return 0;
}
Output:
Example:#include <iostream>
#include <cmath>
int main() {
double x = 100.0;
double log10Value = log10(x);
std::cout << "Base-10 logarithm of " << x << " is: " << log10Value << std::endl;
return 0;
}
Output:
Example:
#include <iostream>
#include <cmath>
int main() {
double x = 16.0;
double log2Value = log2(x);
std::cout << "Base-2 logarithm of " << x << " is: " << log2Value << std::endl;
return 0;
}
Output:
9. Floor: floor(x)
This function returns the largest integer that’s less than or equal to x.
Example:
#include <iostream>
#include <cmath>
int main() {
double x = 4.9;
double floorValue = floor(x);
std::cout << "Floor value of " << x << " is: " << floorValue << std::endl;
return 0;
}
Output:
This function returns the smallest integer that’s greater than or equal to x.
Example:
#include <iostream>
#include <cmath>
int main() {
double x = 4.1;
double ceilValue = ceil(x);
std::cout << "Ceil value of " << x << " is: " << ceilValue << std::endl;
return 0;
}
Output:
Example:
#include <iostream>
#include <cmath>
int main() {
double x = 4.5;
double roundedValue = round(x);
std::cout << "Rounded value of " << x << " is: " << roundedValue << std::endl;
return 0;
}
Output:
Example:
#include <iostream>
#include <cmath>
int main() {
double x = 0.5;
double sineValue = sin(x);
std::cout << "Sine of " << x << " is: " << sineValue << std::endl;
return 0;
}
Output:
Example:#include <iostream>
#include <cmath>
int main() {
double x = 0.5;
double cosineValue = cos(x);
std::cout << "Cosine of " << x << " is: " << sineValue << std::endl;
return 0;
}
Output:
Example:
#include <iostream>
#include <cmath>
int main() {
double x = 0.5;
double tangentValue = tan(x);
std::cout << "Tangent of " << x << " is: " << sineValue << std::endl;
return 0;
}
Output:
Example:
#include <iostream>
#include <cmath>
int main() {
double x = 0.5;
double arcsineValue = asin(x);
std::cout << "Arcsine of " << x << " is: " << sineValue << std::endl;
return 0;
}
Output: