C# :: Aufgabe #334 :: Lösung #3

4 Lösungen Lösungen öffentlich
#334

Primzahlzwillinge (p2 – p1 = 2)

Anfänger - C# von JKooP - 13.10.2020 um 08:52 Uhr
Ein Primzahlzwilling ist ein Paar aus Primzahlen, deren Abstand 2 ist.

Beispiele:

(3, 5), (5, 7), (11, 13), …, (569, 571), …

Schreibe eine Funktion/Methode, die alle Primzahlpaare kleiner 2000 ausgibt.

Viel Spaß
#3
vote_ok
von wolff (40 Punkte) - 31.10.2020 um 00:51 Uhr
Quellcode ausblenden C#-Code
public class Program{

  static void Main(string[] args){
                bool isInt;
                double lastNumber = 0;
                for(double i = 0; i < 2000; i++){
                    isInt = i % 2 == 0;
                    if(isInt == false && i != 1|| isInt == true && i == 2){
                        isInt = i % 3 == 0;
                        if (isInt == false || isInt == true && i == 3){
                            isInt = i % 4 == 0;
                            if (isInt == false){
                                if(i - lastNumber == 2){
                                     System.Console.WriteLine("(" + lastNumber + " | " + i + ")");
                                }
                                lastNumber = i;
                                
                            }
                        }
                    }
                }
            }
         }
      }



Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben