Advertisement
damarijsilva

ejercicio 7 tp0

Aug 18th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics;
  6.  
  7.  
  8.  
  9. namespace ejercicio_5
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             int num = 0;
  16.             int cont = 0;
  17.             Stopwatch tiempo = Stopwatch.StartNew();
  18.  
  19.             while(cont < 10000)
  20.             {
  21.                
  22.                 cont = cont + isPrime(num);
  23.                 num = num + 1;
  24.                 if (cont == 10000)
  25.                 {
  26.                     Console.WriteLine("Hay 10000");                    
  27.                 }
  28.             }
  29.             Console.Write("TIEMPO: " + tiempo.Elapsed.Milliseconds.ToString());
  30.             Console.ReadKey();
  31.         }
  32.  
  33.  
  34.        static int isPrime (int num)
  35.         {
  36.             if ((num == 1) || (num == 2))
  37.             {
  38.                 return 1;
  39.             }
  40.             if ((num % 2) == 0)
  41.             {
  42.                 return 0;
  43.             }
  44.             for (int i = 3; i < num; i = i + 2)
  45.             {
  46.                 if ((num % i) == 0)
  47.                 {
  48.                     return 0;
  49.                 }
  50.             }
  51.             return 1;
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement