You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.4 KiB

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "funktionen.h"
// Function to calculate the square of a number
float square(float x) {
return x * x;
}
float squareRoot(float x) {
if (x >= 0) {
return sqrt(x);
} else {
printf("Error: Invalid input for square root!\n");
return 0;
}
}
// Function to calculate the cube of a number
float cube(float x) {
return x * x * x;
}
// Function to calculate the cube root of a number
float cubeRoot(float x) {
return cbrt(x);
}
// Function to calculate the absolute value of a number
float absolute(float x) {
return fabs(x);
}
// Function to calculate the logarithm (base 10) of a number
float logarithm(float x) {
if (x > 0) {
return log10(x);
} else {
printf("Error: Invalid input for logarithm!\n");
return 0;
}
}
// Function to calculate the natural logarithm (base e) of a number
float naturalLogarithm(float x) {
if (x > 0) {
return log(x);
} else {
printf("Error: Invalid input for natural logarithm!\n");
return 0;
}
}
// Function to calculate the exponentiation of a number to the power of another number
float power(float x, float y) {
return pow(x, y);
}
// Function to calculate the factorial of a number
int factorial(int x) {
if (x >= 0) {
int result = 1;
for (int i = 1; i <= x; i++) {
result *= i;
}
return result;
} else {
printf("Error: Invalid input for factorial!\n");
return 0;
}
}