Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- namespace ejercicio_5
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num = 0;
- int cont = 0;
- Stopwatch tiempo = Stopwatch.StartNew();
- while(cont < 10000)
- {
- cont = cont + isPrime(num);
- num = num + 1;
- if (cont == 10000)
- {
- Console.WriteLine("Hay 10000");
- }
- }
- Console.Write("TIEMPO: " + tiempo.Elapsed.Milliseconds.ToString());
- Console.ReadKey();
- }
- static int isPrime (int num)
- {
- if ((num == 1) || (num == 2))
- {
- return 1;
- }
- if ((num % 2) == 0)
- {
- return 0;
- }
- for (int i = 3; i < num; i = i + 2)
- {
- if ((num % i) == 0)
- {
- return 0;
- }
- }
- return 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement