C#

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday, 9 November 2013

prime or not prime in c sharp


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            anu a = new anu();

            for (int i = 2; i < 10;i++ )

                if (a.prime(i))
                {
                    Console.WriteLine("{0} is not prime:",i);
                }
                else
                    Console.WriteLine("{0} is  prime:", i);
           Console.ReadLine();
       
         int x,y;
         Console.WriteLine("enter both numbers");
         x=Int32.Parse(Console.ReadLine());
         y=Int32.Parse(Console.ReadLine());
         int z;
         z = a.lowestfactor(x,y);
         Console.WriteLine(z);
        }

     }

    class anu
    {
        public bool prime(int x)
        {

            for (int i = 2; i <x; i++)
            {

                if ((x % i) == 0)
                {
                   
                    return true;
                }
         
            }
            return false;

        }
     public int lowestfactor(int a,int b)
     {
         int max;
         if (prime(a) || prime(b))
             return 1;
         max = a < b ? a : b;

         Console.WriteLine(max);
         Console.ReadLine();
         for (int i = 2; i <= max; i++)
         {
             if (((a % i) == 0) && ((b % i) == 0))
                 return i;
         }
         return 1;
   
     }
           

        }
    }


// good program
//2 is  prime
//3 is  prime
//4 is not prime
//5 is  prime
//6 is not prime
//7 is  prime
//8 is not prime
//9 is not prime


     

No comments:

Post a Comment