diff --git a/04 Do_While_Schleife/04 Do_While_Schleife.csproj b/04 Do_While_Schleife/04 Do_While_Schleife.csproj new file mode 100644 index 0000000000000000000000000000000000000000..d63dde6d9ef10774af7ce1b4c388837b508e2404 --- /dev/null +++ b/04 Do_While_Schleife/04 Do_While_Schleife.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_04_Do_While_Schleife</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/04 Do_While_Schleife/Program.cs b/04 Do_While_Schleife/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..c268e67b152ac880d6405c4b84606b99d1b21561 --- /dev/null +++ b/04 Do_While_Schleife/Program.cs @@ -0,0 +1,39 @@ +using System; + +namespace _04_Do_While_Schleife +{ + class Program + { + static void Main(string[] args) + { + bool falscheEingabe; + int zahl; + do + { + Console.Write("Geben Sie eine Zahl zwischen 10..20 ein: "); + zahl = Convert.ToInt32(Console.ReadLine()); + + falscheEingabe = zahl < 10 || zahl > 20; + + if (falscheEingabe) + Console.WriteLine("Falsche Eingabe! Nur Zahlen von 10..20!"); + + } while (falscheEingabe); + + + ////////////////////////////////////////////////////////// + /// Alternativ mit break + + do + { + Console.Write("Geben Sie eine Zahl zwischen 10..20 ein: "); + zahl = Convert.ToInt32(Console.ReadLine()); + + if (zahl >= 10 && zahl <= 20) + break; + + Console.WriteLine("Falsche Eingabe! Nur Zahlen von 10..20!"); + } while (true); + } + } +} diff --git a/04 Dreiecke_Mo_Ubg/04 Dreiecke_Mo_Ubg.csproj b/04 Dreiecke_Mo_Ubg/04 Dreiecke_Mo_Ubg.csproj new file mode 100644 index 0000000000000000000000000000000000000000..80af4ffe22c23e12cb90d4ea569d227d93aff50a --- /dev/null +++ b/04 Dreiecke_Mo_Ubg/04 Dreiecke_Mo_Ubg.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_04_Dreiecke_Mo_Ubg</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/04 Dreiecke_Mo_Ubg/Program.cs b/04 Dreiecke_Mo_Ubg/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..cf9d2ac687a75199d49abd29dbb5c1b80abc4fa0 --- /dev/null +++ b/04 Dreiecke_Mo_Ubg/Program.cs @@ -0,0 +1,49 @@ +using System; + +namespace _04_Dreiecke_Mo_Ubg +{ + class Program + { + static void Quadrat(int n) + { + for (int zeile = 1; zeile <= n; zeile++) + { + for (int spalte = 0; spalte < n; spalte++) + { + Console.Write("X"); + } + Console.WriteLine(); + } + } + static void Dreieck(int n) + { + for (int zeile = 1; zeile <= n; zeile++) + { + for (int spalte = 0; spalte < zeile; spalte++) + { + Console.Write("X"); + } + Console.WriteLine(); + } + } + static void SinPlot() + { + for (double x = 0.0; x < 2*Math.PI; x+=0.1) + { + int anzLeerzeichen = (int)((Math.Sin(x)+1.0)*30.0); + for (int spalte = 0; spalte < anzLeerzeichen; spalte++) + { + Console.Write("."); + } + Console.WriteLine("*"); + } + } + static void Main(string[] args) + { + + Quadrat(4); + Dreieck(15); + SinPlot(); + } + } +} diff --git a/04 IntroFunktionen/04 IntroFunktionen.csproj b/04 IntroFunktionen/04 IntroFunktionen.csproj new file mode 100644 index 0000000000000000000000000000000000000000..2b32c9f08bb4ec51218eed81906c6146959ba14a --- /dev/null +++ b/04 IntroFunktionen/04 IntroFunktionen.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_04_IntroFunktionen</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/04 IntroFunktionen/Program.cs b/04 IntroFunktionen/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..1f5cce18d973181f8f25a00b5b3fd86c2ee478b6 --- /dev/null +++ b/04 IntroFunktionen/Program.cs @@ -0,0 +1,60 @@ +using System; + +namespace _04_IntroFunktionen +{ + class Program + { + // Funktionen ... + // ... kapseln eine Funktionalität (Einfaches Debugging) + // ... unterteilen eine größere Funktionalität in mehrere kleinere + // ... haben lokale Variablen (keine Namenskonflikte mit etwaig gleichlautenden Variablen aus Main) + // Auch die Parametervariablen sind lokale Variable + // ... liefern einen Return-Wert (void = kein Returnwert) + // Eine Funktion kann mehrere return-Anweisungen haben! return beendet die Funktion sofort! + + static bool Primzahltest(int zahl) + { + if (zahl % 2 == 0) + return false; + + int teilergrenze = (int)Math.Sqrt(zahl); + for (int teiler = 3; /* n == 0 && */ teiler <= teilergrenze; teiler += 2) + { + if (zahl % teiler == 0) + return false; + } + return true; + } + + static void dings(int zahl) + { + int xy = 123; + } + static int incr(int zahl) + { + zahl++; + return zahl; + } + + static double kreisflaeche(double r) => Math.PI * r * r; + + + static void Main(string[] args) + { + bool zahlIstPrimzahl = false; + int zahl = 11; + for (int i = 3; i < 25; i++) + { + Console.WriteLine($"{i,4} --> Primzahl={Primzahltest(i)}"); + } + //dings(); + Console.WriteLine(zahlIstPrimzahl); + + zahl = incr(Convert.ToInt32(Console.ReadLine())); + + Console.WriteLine(zahl*zahl); + Console.WriteLine(kreisflaeche(1.5)); + Console.WriteLine(kreisflaeche(Convert.ToDouble(Console.ReadLine()))); + } + } +} diff --git a/04 Schachbrett/04 Schachbrett.csproj b/04 Schachbrett/04 Schachbrett.csproj new file mode 100644 index 0000000000000000000000000000000000000000..46c1e3b99ac9704c2462614afffa7ae267224145 --- /dev/null +++ b/04 Schachbrett/04 Schachbrett.csproj @@ -0,0 +1,9 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>netcoreapp3.1</TargetFramework> + <RootNamespace>_04_Schachbrett</RootNamespace> + </PropertyGroup> + +</Project> diff --git a/04 Schachbrett/Program.cs b/04 Schachbrett/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..091d399f8486db6e9a7df0530aca4754fcabba27 --- /dev/null +++ b/04 Schachbrett/Program.cs @@ -0,0 +1,30 @@ +using System; + +namespace _04_Schachbrett +{ + class Program + { + static void Main(string[] args) + { + bool schwarz = true; + string schwarzFeld = "XXXXX"; + string weissFeld = " "; + for (int z = 0; z < 8; z++) + { + for (int n = 0; n < 3; n++) + { + for (int s = 0; s < 8; s++) + { + if (schwarz) + Console.Write(schwarzFeld); + else + Console.Write(weissFeld); + schwarz = !schwarz; + } + Console.WriteLine(); + } + schwarz = !schwarz; + } + } + } +} diff --git a/Prog1_WS2021_22.sln b/Prog1_WS2021_22.sln index 995f82496d423661a8d1c488910b1d8250f0671f..1a54378e98d28e7bd14395f9a61e8b98c53e3718 100644 --- a/Prog1_WS2021_22.sln +++ b/Prog1_WS2021_22.sln @@ -15,17 +15,25 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "02 Ausgabeformatierung", "0 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "02 Fallunterscheidungen", "02 Fallunterscheidungen\02 Fallunterscheidungen.csproj", "{3370BE4E-7EF8-4ABB-949D-62CA9FA5CDA7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "03 SchleifenIntro", "03 SchleifenIntro\03 SchleifenIntro.csproj", "{5C715673-820D-4FC5-B8C6-EEE0890713EE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "03 SchleifenIntro", "03 SchleifenIntro\03 SchleifenIntro.csproj", "{5C715673-820D-4FC5-B8C6-EEE0890713EE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "03 Primzahltest", "03 Primzahltest\03 Primzahltest.csproj", "{958EC31B-7CFC-470B-87AD-2AEB00E816A5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "03 Primzahltest", "03 Primzahltest\03 Primzahltest.csproj", "{958EC31B-7CFC-470B-87AD-2AEB00E816A5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "03 IntArithmetik", "03 IntArithmetik\03 IntArithmetik.csproj", "{9CB8537D-D35E-4718-9258-12857B8B7411}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "03 IntArithmetik", "03 IntArithmetik\03 IntArithmetik.csproj", "{9CB8537D-D35E-4718-9258-12857B8B7411}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "03 IntArithmetik_Di", "03 IntArithmetik_Di\03 IntArithmetik_Di.csproj", "{EADEA381-506F-41FF-99EC-487D4D3B6114}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "03 IntArithmetik_Di", "03 IntArithmetik_Di\03 IntArithmetik_Di.csproj", "{EADEA381-506F-41FF-99EC-487D4D3B6114}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "03 Quersumme", "03 Quersumme\03 Quersumme.csproj", "{C2D51C5D-AFDC-4A8A-9393-904A1CAA2CCC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "03 Quersumme", "03 Quersumme\03 Quersumme.csproj", "{C2D51C5D-AFDC-4A8A-9393-904A1CAA2CCC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "03 Quadratzahlen_bis", "03 Quadratzahlen_bis\03 Quadratzahlen_bis.csproj", "{F492AB76-864B-45FD-9BF2-36B9CA24987D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "03 Quadratzahlen_bis", "03 Quadratzahlen_bis\03 Quadratzahlen_bis.csproj", "{F492AB76-864B-45FD-9BF2-36B9CA24987D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "04 Schachbrett", "04 Schachbrett\04 Schachbrett.csproj", "{4C1097BC-5773-43BA-A40E-DF2E66BFCE81}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "04 Do_While_Schleife", "04 Do_While_Schleife\04 Do_While_Schleife.csproj", "{C208A9CA-81BF-4514-ABD7-107162940C1E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "04 IntroFunktionen", "04 IntroFunktionen\04 IntroFunktionen.csproj", "{B22C3D1C-0375-451F-885F-51015FE6633C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "04 Dreiecke_Mo_Ubg", "04 Dreiecke_Mo_Ubg\04 Dreiecke_Mo_Ubg.csproj", "{40E4407D-F055-463C-96E6-63F948EF19E7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -81,6 +89,22 @@ Global {F492AB76-864B-45FD-9BF2-36B9CA24987D}.Debug|Any CPU.Build.0 = Debug|Any CPU {F492AB76-864B-45FD-9BF2-36B9CA24987D}.Release|Any CPU.ActiveCfg = Release|Any CPU {F492AB76-864B-45FD-9BF2-36B9CA24987D}.Release|Any CPU.Build.0 = Release|Any CPU + {4C1097BC-5773-43BA-A40E-DF2E66BFCE81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4C1097BC-5773-43BA-A40E-DF2E66BFCE81}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C1097BC-5773-43BA-A40E-DF2E66BFCE81}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4C1097BC-5773-43BA-A40E-DF2E66BFCE81}.Release|Any CPU.Build.0 = Release|Any CPU + {C208A9CA-81BF-4514-ABD7-107162940C1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C208A9CA-81BF-4514-ABD7-107162940C1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C208A9CA-81BF-4514-ABD7-107162940C1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C208A9CA-81BF-4514-ABD7-107162940C1E}.Release|Any CPU.Build.0 = Release|Any CPU + {B22C3D1C-0375-451F-885F-51015FE6633C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B22C3D1C-0375-451F-885F-51015FE6633C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B22C3D1C-0375-451F-885F-51015FE6633C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B22C3D1C-0375-451F-885F-51015FE6633C}.Release|Any CPU.Build.0 = Release|Any CPU + {40E4407D-F055-463C-96E6-63F948EF19E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40E4407D-F055-463C-96E6-63F948EF19E7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40E4407D-F055-463C-96E6-63F948EF19E7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40E4407D-F055-463C-96E6-63F948EF19E7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE