elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Hacer sin Arreglos NI EL USO DEL SETCURSORPOSITION
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Hacer sin Arreglos NI EL USO DEL SETCURSORPOSITION  (Leído 1,915 veces)
Choclito

Desconectado Desconectado

Mensajes: 99



Ver Perfil
Hacer sin Arreglos NI EL USO DEL SETCURSORPOSITION
« en: 6 Julio 2009, 18:53 pm »

hola a todoso mire el programa que toy haciendo es que yo ingrese un Limite Inferior y un Limite Superior y me Muestre todos los primos en ese intervalo
y despues los primos anteriores a este primo osea ejemplo masomenos

Li=1 Ls=12

me mostrara en el modo consola

1 2 3 5 7 11
   1 2 3 5  7
      1 2 3  5
          1 2 3
             1 2
                1

 NOTA:HACER ESTE PROGRAMA SIN ARREGLOS NI UsO DE SETCURSOTIONPOSITION

YO LO HIZE MASOMENOS ASI SI TIENES ESA SOLUCION ME GUSTARIA QUE LA COMPATIERAN GRACIAS

using System;
using System.Collections.Generic;
using System.Text;

namespace la_suma_de_primos
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = new int[50];
            int a, b, C = 0, i, j, cp = 0;            
            Console.WriteLine("\t\tSUMA DE NUMEROS PRIMOS");
            Console.Write("*INGRESAR PRIMER INTERVALO: ");
            a = int.Parse(Console.ReadLine());
            Console.Write("*INGRESAR SEGUNDO INTERVALO: ");
            b = int.Parse(Console.ReadLine());
            for (i = a; i <= b; i++)
            {
                for (j = 1; j <= i; j++)
                {
                    if (i % j == 0)
                    {
                        C = C + 1;
                    }
                }
                if (C <= 2)
                {                  
                    //contando primos
                    cp = cp + 1;
                    // Console.WriteLine("={0}",i);
                    arr[cp] = i;
                }
                C = 0;
            }        
            for (i = 1; i <= cp; i++)
            {
                Console.Write(" \t{0} ", arr);                
            }
            Console.WriteLine();      
            j = 1;
            int mayor = arr[cp] * cp;
            for (i = 1; i <= mayor; i++)
            {
                arr[j] -= 1;          
                arr[j] = CapturaPrimo(arr[j]);
                if (arr[j] > 0)
                {
                    Console.Write(" \t{0} ", arr[j]);                    
                }
                else
                    Console.Write(" \t ");
                if (j == cp)
                {
                    j = 1;
                    Console.WriteLine();
                }
                else
                    j++;
            }            
            Console.ReadLine();
        }

        private static int CapturaPrimo(int p)
        {
            while (p > 0)
            {
                if (EsPrimo(p))
                {
                    return p;
                }
                else
                    p--;
            }
            return p;
        }

        private static bool EsPrimo(int p)
        {
            int c = 0;
            for (int i = 1; i <= p; i++)
            {
                if (p % i == 0)
                {
                    c++;
                }                
            }
            if (c <= 2)
            {
                return true;
            }
            else
                return false;
        }
    }
}


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[C] Explicación de cómo hacer arreglos multidimensionales dinámicos
Programación C/C++
eenube 1 2,029 Último mensaje 15 Marzo 2016, 18:41 pm
por MAFUS
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines