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

1 year ago
1 year ago
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <math.h>
  5. #include "funktionen.h"
  6. // Function to calculate the square of a number
  7. float square(float x) {
  8. return x * x;
  9. }
  10. float squareRoot(float x) {
  11. if (x >= 0) {
  12. return sqrt(x);
  13. } else {
  14. printf("Error: Invalid input for square root!\n");
  15. return 0;
  16. }
  17. }
  18. // Function to calculate the cube of a number
  19. float cube(float x) {
  20. return x * x * x;
  21. }
  22. // Function to calculate the cube root of a number
  23. float cubeRoot(float x) {
  24. return cbrt(x);
  25. }
  26. // Function to calculate the absolute value of a number
  27. float absolute(float x) {
  28. return fabs(x);
  29. }
  30. // Function to calculate the logarithm (base 10) of a number
  31. float logarithm(float x) {
  32. if (x > 0) {
  33. return log10(x);
  34. } else {
  35. printf("Error: Invalid input for logarithm!\n");
  36. return 0;
  37. }
  38. }
  39. // Function to calculate the natural logarithm (base e) of a number
  40. float naturalLogarithm(float x) {
  41. if (x > 0) {
  42. return log(x);
  43. } else {
  44. printf("Error: Invalid input for natural logarithm!\n");
  45. return 0;
  46. }
  47. }
  48. // Function to calculate the exponentiation of a number to the power of another number
  49. float power(float x, float y) {
  50. return pow(x, y);
  51. }
  52. // Function to calculate the factorial of a number
  53. int factorial(int x) {
  54. if (x >= 0) {
  55. int result = 1;
  56. for (int i = 1; i <= x; i++) {
  57. result *= i;
  58. }
  59. return result;
  60. } else {
  61. printf("Error: Invalid input for factorial!\n");
  62. return 0;
  63. }
  64. }