You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Klausur07122016_2
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
//Aufgabe 2) Messwerte auswerten
|
|
|
|
|
//erstellt von Alexander Degen BS IT16
|
|
|
|
|
|
|
|
|
|
//Deklaration der Variablen
|
|
|
|
|
Random zufall = new Random(20161207);
|
|
|
|
|
int[] messwerte = new int[1000];
|
|
|
|
|
int anz1er = 0;
|
|
|
|
|
int anz0er = 0;
|
|
|
|
|
int start0erSequenz = 0;
|
|
|
|
|
int länge0erSequenz = 0;
|
|
|
|
|
int start0erSequenzMax = 0;
|
|
|
|
|
int max0erSequenz = 0;
|
|
|
|
|
|
|
|
|
|
//Header
|
|
|
|
|
Console.WriteLine("---Binärmesswertermittler--- \n\n");
|
|
|
|
|
|
|
|
|
|
//Array-Handling
|
|
|
|
|
for (int i = 0; i < messwerte.GetLength(0); i++)
|
|
|
|
|
{
|
|
|
|
|
//Füllen des Arrays
|
|
|
|
|
messwerte[i] = zufall.Next(0, 2);
|
|
|
|
|
|
|
|
|
|
//Zählen der 1er und 0er
|
|
|
|
|
if (messwerte[i] == 1)
|
|
|
|
|
anz1er++;
|
|
|
|
|
else
|
|
|
|
|
anz0er++;
|
|
|
|
|
|
|
|
|
|
//Sequenz ermitteln
|
|
|
|
|
if (messwerte[i] == 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (länge0erSequenz == 0)
|
|
|
|
|
start0erSequenz = i;
|
|
|
|
|
|
|
|
|
|
länge0erSequenz++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (länge0erSequenz > max0erSequenz)
|
|
|
|
|
{
|
|
|
|
|
max0erSequenz = länge0erSequenz;
|
|
|
|
|
start0erSequenzMax = start0erSequenz;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
länge0erSequenz = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Ausgabe
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("\n Anzahl 0er : " + anz0er);
|
|
|
|
|
Console.WriteLine("\n Anzahl 1er : " + anz1er);
|
|
|
|
|
Console.WriteLine("\n Beginn der größten 0er Sequenz: " + start0erSequenzMax);
|
|
|
|
|
Console.WriteLine("\n Länge der größten 0er Sequenz: " + max0erSequenz);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.ReadLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|