diff --git a/Bezugspreis/Bezugspreis.cs b/Bezugspreis/Bezugspreis.cs new file mode 100644 index 0000000000000000000000000000000000000000..c441b2b443c47b9a512b50abccbdbdb3fa6021c7 --- /dev/null +++ b/Bezugspreis/Bezugspreis.cs @@ -0,0 +1,35 @@ +// Funktion zur Berechnung eines Bezugspreises unter Berücksichtigung von +// Versandkosten und Rabatt +static double Bezugspreis(double listenPreis, int versandArt, double rabatt = 0) +{ + // Variable für Return-Wert + double preis = listenPreis; + + // Rabatt-Berechnung + if (rabatt < 0) + return -1; // Fehlerfall + preis -= preis * rabatt / 100.0; + + // Versandkosten-Berechnung - hier mal mit switch-Expression + double porto = versandArt switch + { + 1 => 4.90, // Päckchen + 2 => 6.50, // Paket < 10kg + 3 => 12.00, // Paket > 10kg + _ => -1 // Fehlerfall + }; + if (porto < 0) + return -1; // Fehlerfall + + preis += porto; + + return preis; +} + +Console.WriteLine($"Fall 1: Preis = {Bezugspreis(125, 2, 10):0.00} Euro"); +Console.WriteLine($"Fall 2: Preis = {Bezugspreis(200, 1, 3):0.00} Euro"); +Console.WriteLine($"Fall 3: Preis = {Bezugspreis(375, 3, 0):0.00} Euro"); +Console.WriteLine($"Fehler: Preis = {Bezugspreis(50, 4, 0):0.00} Euro"); +Console.WriteLine($"Fehler: Preis = {Bezugspreis(150, 1, -1):0.00} Euro"); + +Console.ReadKey(); diff --git a/Bezugspreis/Bezugspreis.csproj b/Bezugspreis/Bezugspreis.csproj new file mode 100644 index 0000000000000000000000000000000000000000..206b89a9a8b9320db4b017a262b565f104489193 --- /dev/null +++ b/Bezugspreis/Bezugspreis.csproj @@ -0,0 +1,10 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net8.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/PotenzFunktion/PotenzFunktion.cs b/PotenzFunktion/PotenzFunktion.cs new file mode 100644 index 0000000000000000000000000000000000000000..dc98737f223277d747bf2e6f288e4d0ffe0b7016 --- /dev/null +++ b/PotenzFunktion/PotenzFunktion.cs @@ -0,0 +1,28 @@ +namespace Uebung +{ + class Program + { + // Potenzfunktion + static double Potenz(double x, int n) + { + double potenz = 1; + + for (int i = 1; i <= n; i++) + potenz *= x; + + return potenz; + } + + // Hauptprogramm + static void Main() + { + Console.Write("Basis eingeben: "); + double basis = Convert.ToDouble(Console.ReadLine()); + Console.Write("Exponent eingeben: "); + int exponent = Convert.ToInt32(Console.ReadLine()); + + for (int i = 0; i <= exponent; i++) + Console.WriteLine($"{basis}^{i}: {Potenz(basis, i),4}"); + } + } +} \ No newline at end of file diff --git a/PotenzFunktion/PotenzFunktion.csproj b/PotenzFunktion/PotenzFunktion.csproj new file mode 100644 index 0000000000000000000000000000000000000000..40c60dd4c884340c455eab8a0020f7c681a4e76c --- /dev/null +++ b/PotenzFunktion/PotenzFunktion.csproj @@ -0,0 +1,10 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/QuerZahlen/QuerZahlen.cs b/QuerZahlen/QuerZahlen.cs new file mode 100644 index 0000000000000000000000000000000000000000..d764bff951a71f4556124aa65cd92b8153242040 --- /dev/null +++ b/QuerZahlen/QuerZahlen.cs @@ -0,0 +1,48 @@ +namespace Uebung +{ + class Program + { + static int QuerSumme(int zahl) + { + int summe = 0; + while (zahl > 0) + { + summe += zahl % 10; + zahl /= 10; + } + + return summe; + } + + static int QuerProdukt(int zahl) + { + if (zahl == 0) + return 0; + + int produkt = 1; + while (zahl > 0) + { + produkt *= zahl % 10; + zahl /= 10; + } + + return produkt; + } + + static bool IstQuerZahl(int zahl) + { + return QuerSumme(zahl) + QuerProdukt(zahl) == zahl; + } + + // Hauptprogramm + static void Main() + { + for (int zahl = 2; zahl < 1000; zahl++) + { + // Console.WriteLine($"{zahl,5} {QuerSumme(zahl),5} {QuerProdukt(zahl),5}"); + if (IstQuerZahl(zahl)) + Console.WriteLine($"{zahl} ist eine Querzahl!"); + } + } + } +} \ No newline at end of file diff --git a/QuerZahlen/QuerZahlen.csproj b/QuerZahlen/QuerZahlen.csproj new file mode 100644 index 0000000000000000000000000000000000000000..40c60dd4c884340c455eab8a0020f7c681a4e76c --- /dev/null +++ b/QuerZahlen/QuerZahlen.csproj @@ -0,0 +1,10 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/Twist/Twist.cs b/Twist/Twist.cs new file mode 100644 index 0000000000000000000000000000000000000000..3d1e2e52d02f17fc015b9d4a45ac79799689b88d --- /dev/null +++ b/Twist/Twist.cs @@ -0,0 +1,19 @@ +static int Twist(int zahl) +{ + int twist = 0; + + while (zahl > 0) + { + int ziffer = zahl % 10; + twist = twist * 10 + ziffer; + zahl /= 10; + } + + return twist; +} + +// Hauptprogramm +int zahl = 4567; +Console.WriteLine($"{zahl} umgekehrt: {Twist(zahl)}"); +zahl = 1234567890; +Console.WriteLine($"{zahl} umgekehrt: {Twist(zahl)}"); diff --git a/Twist/Twist.csproj b/Twist/Twist.csproj new file mode 100644 index 0000000000000000000000000000000000000000..40c60dd4c884340c455eab8a0020f7c681a4e76c --- /dev/null +++ b/Twist/Twist.csproj @@ -0,0 +1,10 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project> diff --git a/Uebung05.sln b/Uebung05.sln new file mode 100644 index 0000000000000000000000000000000000000000..89a5a1a3f40c4c2457d04398880a6ea60df38ba0 --- /dev/null +++ b/Uebung05.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PotenzFunktion", "PotenzFunktion\PotenzFunktion.csproj", "{EC9A3624-8777-41A5-A708-E3765BE52E5A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuerZahlen", "QuerZahlen\QuerZahlen.csproj", "{CC129094-DD5F-4AB8-B685-59F8A9E6694A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Twist", "Twist\Twist.csproj", "{2EB67C10-2D6D-4283-AD11-240C8CE010C3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bezugspreis", "Bezugspreis\Bezugspreis.csproj", "{92656707-21E5-48D2-9FB1-E43A584DDD9D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EC9A3624-8777-41A5-A708-E3765BE52E5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EC9A3624-8777-41A5-A708-E3765BE52E5A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EC9A3624-8777-41A5-A708-E3765BE52E5A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EC9A3624-8777-41A5-A708-E3765BE52E5A}.Release|Any CPU.Build.0 = Release|Any CPU + {CC129094-DD5F-4AB8-B685-59F8A9E6694A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CC129094-DD5F-4AB8-B685-59F8A9E6694A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CC129094-DD5F-4AB8-B685-59F8A9E6694A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CC129094-DD5F-4AB8-B685-59F8A9E6694A}.Release|Any CPU.Build.0 = Release|Any CPU + {2EB67C10-2D6D-4283-AD11-240C8CE010C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2EB67C10-2D6D-4283-AD11-240C8CE010C3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2EB67C10-2D6D-4283-AD11-240C8CE010C3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2EB67C10-2D6D-4283-AD11-240C8CE010C3}.Release|Any CPU.Build.0 = Release|Any CPU + {92656707-21E5-48D2-9FB1-E43A584DDD9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {92656707-21E5-48D2-9FB1-E43A584DDD9D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {92656707-21E5-48D2-9FB1-E43A584DDD9D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {92656707-21E5-48D2-9FB1-E43A584DDD9D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C3F003FC-52A5-4A88-9F70-94B7949BBBFC} + EndGlobalSection +EndGlobal diff --git a/ZeichneDreieck/Dreieck.cs b/ZeichneDreieck/Dreieck.cs new file mode 100644 index 0000000000000000000000000000000000000000..99ee393070e51413435dd7bc0c173a3e12abfba4 --- /dev/null +++ b/ZeichneDreieck/Dreieck.cs @@ -0,0 +1,42 @@ +class Program +{ + static void ZeichneDreieck(int n, char c = '*', bool zentriert = false) + { + // Man könnte jetzt die beiden Code-Blöcke auch in einen zusammenfassen, + // weil die Schleifen ja im Prinzip das Gleiche machen. + // Versuchen Sie mal, den Code umzustellen! + if (!zentriert) + { + for (int i = 1; i <= n; i++) + { + for (int j = 1; j <= i; j++) + Console.Write(c); + + Console.WriteLine(); + } + } + else // zentriert + { + for (int i = 1, leer = n-1; i <= n; i++, leer--) + { + // Leerzeichen vorher einfügen + for (int j = 1; j <= leer; j++) + Console.Write(' '); + + for (int j = 1; j <= 2 * i - 1; j++) + Console.Write(c); + + Console.WriteLine(); + } + } + } + + static void Main() + { + ZeichneDreieck(6, '$'); + Console.WriteLine(); + ZeichneDreieck(3); + Console.WriteLine(); + ZeichneDreieck(5, '#', true); + } +} \ No newline at end of file diff --git a/ZeichneDreieck/ZeichneDreieck.csproj b/ZeichneDreieck/ZeichneDreieck.csproj new file mode 100644 index 0000000000000000000000000000000000000000..40c60dd4c884340c455eab8a0020f7c681a4e76c --- /dev/null +++ b/ZeichneDreieck/ZeichneDreieck.csproj @@ -0,0 +1,10 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + +</Project>