<sub class="descriptionSection">24-10-2024 02:32:pm // #Tag // [[Programmierung]]</sub> ____ ```cpp #include <iostream> #define _USE_MATH_DEFINES #include <cmath> using namespace std; void kreis(const double radius, double &umfang, double &flaeche){ flaeche = 2 * M_PI * (radius * radius); umfang = 2 * radius * M_PI; } int main() { double r, u, f; r = 0.5; kreis(r, u, f); cout << f << endl; cout << u << endl; return 0; } ``` ## Rechtwinkliges dreieck ```cpp #include <iostream> #define _USE_MATH_DEFINES #include <cmath> using namespace std; double bogenMassRechnen(double winkel){ return (winkel/360.0) * (2.0 * M_PI); } void calculateSides(double alpha, double hypothenuse, double &a, double &b){ double beta = 180.0 - alpha - 90.0; cout << beta << endl; a = sin(bogenMassRechnen(alpha)) * hypothenuse; b = cos(bogenMassRechnen(alpha)) * hypothenuse; } int main() { double a = 0.0, b = 0.0; calculateSides(38.66, 6.4, a, b); cout << a << endl; cout << b << endl; return 0; } ``` ## Zusatzaufgabe Tauschen ```cpp #include <iostream> #define _USE_MATH_DEFINES #include <cmath> using namespace std; void tauschen(int &a, int &b){ int hilf = a ; a = b; b = hilf; } int main() { int a = 20; int b = 0; tauschen(a, b); cout << a << " " << b << endl; return 0; } ``` ## Expertenaufgabe Sortieren ```cpp #include <iostream> using namespace std; void tauschen(float &a, float &b){ float hilf = a ; a = b; b = hilf; } unsigned int sortiere(float &x, float &y, float &z){ unsigned int counter = 0; while(x > y || y > z) { if(x > y) { tauschen(x, y); counter++; } if(y > z) { tauschen(y, z); counter++; } } return counter; } int main() { int counter = 0; float x = 320, y = 65, z = 120; unsigned int anzahl = sortiere(x, y , z); cout << x << ' ' << y << ' ' << z << endl; cout << anzahl << endl; return 0; } ```