Last active
December 27, 2015 05:39
-
-
Save d8ta/7276077 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 1310601027, fhs36118 | |
* Daniel Raudschus | |
* ueo3 bsp15 | |
*/ | |
using System; | |
namespace bsp15 | |
{ | |
/* 15. (1P) Eine Formel zur Generierung von Primzahlen ist Eulers Primzahlformel: | |
p(x) = x2 + x + 41 | |
Implementiere diese Funktion als generatePrime() mit entsprechendem Rückgabewert. | |
überprüfe anschließend die Behauptung, dass die oben angegebene Formel für x = 0,1,2... Primzahlen liefert, | |
empirisch für alle x:0 ≤ x < 100 steht. Nutze dazu die isPrime() Funktion. | |
Gib dabei für jedes x aus, ob p(x) prim oder nicht prim ist: | |
p(0) = 41 ist prim. | |
p(1) = 43 ist prim. | |
... | |
p(65) = 4331 ist nicht prim. | |
... | |
*/ | |
class MainClass | |
{ | |
public static void Main (string[] args) | |
{ | |
isPrime ( generatePrime(2) ); // will statt der zwei hier ein var. haben die autom von 0 - 100 hochzählt | |
} | |
// write the generatePrime()function | |
public static int generatePrime( int genNum ) | |
{ | |
genNum = (((genNum * genNum) + genNum) + 41); | |
Console.WriteLine ("Number generated by Eulers formular is: " + genNum); | |
return genNum; | |
} | |
// implement isPrime function to check the formular | |
public static bool isPrime( int eNum ) | |
{ | |
for ( int counter = 1; counter < 100; counter ++ ) | |
{ | |
if (eNum % counter == 0) { | |
Console.WriteLine ( eNum + " is Prime!" ); | |
return false; | |
} else { | |
Console.WriteLine( eNum + " is not Prime" ); | |
} | |
} | |
return true; | |
} | |
// TODO give back a result like p(x) = 14 is prime and count from eNum 0 - 100 !! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment