Advertisement
ralichka

More.Exercises.Nested.Loops-13.Prime.Pairs

Jul 19th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _13.PrimePairs
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int startFirstCouple = int.Parse(Console.ReadLine());
  10.             int startSecondCouple = int.Parse(Console.ReadLine());
  11.             int diffFirstCouple = int.Parse(Console.ReadLine());
  12.             int diffSecondCouple = int.Parse(Console.ReadLine());
  13.  
  14.             int endFirstCouple = startFirstCouple+diffFirstCouple;
  15.             int endSecondCouple = startSecondCouple+diffSecondCouple;
  16.  
  17.             for (int i = startFirstCouple; i <=endFirstCouple; i++)
  18.             {
  19.              
  20.                 for (int j = startSecondCouple; j <=endSecondCouple; j++)
  21.                 {
  22.                     bool primeFirst = true;
  23.  
  24.                     for (int primeNumFirst = 2; primeNumFirst <= i/2; primeNumFirst++)
  25.                     {
  26.                         if (i % primeNumFirst == 0)
  27.                         {
  28.                             primeFirst = false;
  29.                            
  30.                         }
  31.                     }
  32.  
  33.                     bool primeSecond = true;
  34.  
  35.                     for (int primeNumSecond = 2; primeNumSecond <= j/2; primeNumSecond++)
  36.                     {
  37.                         if (j % primeNumSecond == 0)
  38.                         {
  39.                             primeSecond = false;
  40.                            
  41.                         }
  42.                     }
  43.                    if (primeFirst && primeSecond)
  44.                     {
  45.                         Console.WriteLine($"{i}{j}");
  46.                     }
  47.                        
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement