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.Threading.Tasks;
- namespace TP0_Ejerc7
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Los números primos son:");
- DateTime inicio = DateTime.Now;
- int acumulador = 0;
- int n = 2;
- while (acumulador<=10000)
- {
- if (n == 2)
- {
- Console.Write(n + ", ");
- n++;
- }
- else
- {
- if (isprime(n))
- {
- if (acumulador < 10000)
- {
- Console.Write(n + ", ");
- acumulador++;
- n += 2;
- }
- else
- {
- Console.WriteLine(n);
- acumulador++;
- }
- }
- else
- {
- n += 2;
- }
- }
- }
- DateTime fin = DateTime.Now;
- Console.WriteLine("El tiempo de ejecución del algortimo es: " + (fin - inicio));
- Console.ReadKey();
- }
- static bool isprime(int n)
- {
- for (int i = 3; i < n; i += 2)
- {
- if (n % i == 0)
- {
- return false;
- }
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement