Advertisement
Mitoeap

Generador Números Primos

Aug 11th, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. namespace NumerosPrimos
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main (string[] args)
  8.         {
  9.             Console.WriteLine ("Ingrese la cantidad de números primos generar");
  10.             String cantnumeros = Console.ReadLine();
  11.             int cant = Convert.ToInt32 (cantnumeros);
  12.             int contador = 1;
  13.             int primo = 2;
  14.             int divisor = 2;
  15.             while (contador <= cant) {
  16.                 if (primo % divisor == 0) {
  17.                     if (primo == divisor) {
  18.                         Console.Write(primo + ", ");
  19.                         contador++;
  20.                     }
  21.                     divisor = 2;
  22.                     primo++;
  23.                 }
  24.                 else
  25.                     divisor++;
  26.             }
  27.             Console.ReadKey ();
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement