jueves, 20 de marzo de 2014

Tabla de multipliar y los 10 primeros numeros primos

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace practica_1
{
    class Program
    {
        static void Main(string[] args)
        {
        Console.WriteLine("HOLA A TODOS");
        Console.BackgroundColor = ConsoleColor.Blue;
        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine("ESTA ES MI PRIMERA APLICACION EN C#");
        int c, n1, n2, n5, n6, n7, r, i, j, k,r1,r2,r3;
           
           
           
            Console.Write("Ingrese el valor inicial : ");
        n5 = Convert.ToInt16(Console.ReadLine());
        Console.Write("Ingrese un valor final : ");
        n6 = Convert.ToInt16(Console.ReadLine());
        Console.Write("Ingrese el numero de multiplicar : ");
        n7 = Convert.ToInt16(Console.ReadLine());
           
        Console.WriteLine("Tabla de multiplicar con el bucle FOR");
        for (i = n5; i <= n6; i++)
        {
            r1 = i * n7;
            Console.WriteLine("{0} x {1} = {2}", i, n7, r1);   
        }
           
        Console.WriteLine("Tabla de multiplicar con el bucle DO");
        j = n5;
        do
        {
            r2 = j * n7;
            Console.WriteLine("{0} x {1} = {2}", j, n7, r2);
            j++;
        } while (j <= n6);
           
        Console.WriteLine("Tabla de multiplicar con el bucle WHILE");
        k = n5;
        while (k <= n6)
        {
            r3 = k * n7;
            Console.WriteLine("{0} x {1} = {2}", k, n7, r3);
            k++;
        }

          
            c = 0;
           
            int cont = 0;
            Console.WriteLine("Los 10 primeros numeros primos con el bucle FOR son:");
            for (i = 1; i <= 25; i++)
            {
                for (j = 1; j<= i; j++)
                {
                    if (i % j == 0)
                    {
                        cont = cont + 1;
                    }
                }
                if (cont < 3)
                {
                    Console.WriteLine(i);
                }
                cont = 0;
            }
            Console.WriteLine("Los 10 primeros numeros primos con el bucle DO son:");
           
            i = 0;
            cont = 0;
            do
            {
                i++;
                j = 0;
                do
                {
                    j++;
                    if (i % j == 0)
                    {
                        cont = cont + 1;
                     
                    }

                   
                } while (i>=j);

                if (cont < 3 && cont > 0)
                {
                    Console.WriteLine(i);
                }
                cont = 0;
               
            } while (i<=25);


            Console.WriteLine("Los 10 primeros numeros primos con el bucle WHILE son:");
            i = 0;
            cont = 0;
            while (i<=25)
            {

                i++;
                j = 0;
                while (i >= j)
                {
                    j++;
                    if (i % j == 0)
                    {
                        cont = cont + 1;

                    }


                }

                if (cont < 3 && cont > 0)
                {
                    Console.WriteLine(i);
                }
                cont = 0;
               
            }
               
            Console.ReadLine();
  
       
        }
    }
}

No hay comentarios:

Publicar un comentario