Thursday, March 27, 2014

Binary to decimal by c#

namespace binary_to_decimal
{
    class Program
    {
        static void Main(string[] args)
        {
            object r;
            long i,n,sum = 0,k=0,u;
            Console.WriteLine("enter the no of degit of the no");
            n = Int64.Parse(Console.ReadLine());
            u = Int64.Parse(Console.ReadLine());
            r = u;
            Console.WriteLine("the no" + r);
               
            long[] b = new long[n];
            Console.WriteLine("enter the no");
            for (i = 0; i < n; i++)
            {
                b[i] = Int64.Parse(Console.ReadLine());
            }
            for (i = n-1; i >=0; i--)
            {
                sum = sum + b[i] * (int)Math.Pow(2, k);
                k++;
            }
            Console.WriteLine("the no is " + sum);

        }
    }
}

complex no in c#

using System.Text;

namespace compalx_no
{
    class complex
    {
        double a, b, c, d;
        public complex(double v, double x)
        {
            a = v;
            b = x;
        }
        public complex mul(complex t, complex r)
        {
            c = t.a * r.a - t.b * r.b;
            d = t.a * r.b + t.b * r.a;
            t.a = c;
            t.b = d;
            return t;


        }
        public complex()
        {
        }
        public void display()
        {
            Console.WriteLine("The result of the complex number" + a + "i" + b);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            complex s = new complex(2, 3);
            complex w = new complex(4, 1);
            complex p = new complex();
            p = s.mul(s, w);
            p.display();
        }
    }
}