Commit 19300305 authored by Claudio Hoffmann's avatar Claudio Hoffmann

Praktikum 3 fertig

parent 8b4ddeac

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.15
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Praktikum3", "Praktikum3\Praktikum3.csproj", "{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9926DAC5-8475-4A38-A76A-4722B9CBE5C1}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Praktikum3</RootNamespace>
<AssemblyName>Praktikum3</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Praktikum3
{
class Program
{
static double Alternierend1(uint summanden)
{
double erg = 0.0;
// Spart uns die Fallunterscheidung, wenn man die
// Richtung immer zwischen 1.0 und -1.0 wechseln lässt.
double richtung = 1.0;
for (uint n = 1; n <= summanden; n++)
{
erg += richtung / n;
richtung = -richtung;
}
return erg;
}
static double Alternierend2(uint summanden)
{
double erg = 0.0;
// Alle ungeraden Summanden (1, 3, 5, …) sind positiv.
for (uint n = 1; n <= summanden; n += 2)
{
erg += 1.0 / n;
}
// Alle geraden Summanden (2, 4, 6, …) sind negativ.
for (uint n = 2; n <= summanden; n += 2)
{
erg -= 1.0 / n;
}
return erg;
}
// Unabhängig von n, daher kein Parameter.
static double Alternierend3()
{
double erg = 0.0;
// So, wie die Aufgabenstellung formuliert ist, muss
// der Summand immer positiv bleiben, also müssen wir
// die Richtung hier separat betrachten.
int richtung = 1;
double summand = 1.0;
uint n = 1;
while(summand >= 0.0001)
{
erg += richtung * summand;
n++;
richtung = -richtung;
summand = 1.0 / n;
}
return erg;
}
static void Main(string[] args)
{
// Eine negative Anzahl ergibt hier keinen Sinn.
uint summanden;
Console.WriteLine("Berechnung der alternierenden Reihe");
Console.WriteLine("-----------------------------------");
Console.Write("Wie viele Summanden? ");
summanden = Convert.ToUInt32(Console.ReadLine());
if (summanden == 0)
{
Console.WriteLine("0 Summanden? Was soll da rauskommen?");
return;
}
Console.WriteLine("Variante 1: {0}", Alternierend1(summanden));
Console.WriteLine("Variante 2: {0}", Alternierend2(summanden));
Console.WriteLine("Variante 3: {0}", Alternierend3());
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Praktikum2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Praktikum2")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9926dac5-8475-4a38-a76a-4722b9cbe5c1")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment