Wednesday, 4 March 2015

//Write a program to create an interface and display maximum value using three variables.
using System;
interface myinterface
{
    string getdata(int a, int b, int c);
}
class b : myinterface
{
    public string getdata(int a, int b, int c)
    {
        if (a > b && a > c)
            return "A is Max";
        else if (b > c && b > a)
            return "B is Max";
        else if (c > a && c > b)
            return "C is Max";
        else if (a == b && a > c)
            return "A  & B is Max";
        else if (b == c && b > a)
            return "B  & C is Max";
        else if (c == a && c > b)
            return "C  & A is Max";
        else
            return "A & B & C Are Max";
    }
}
class myclass
{
    public static void Main()
    {
        int a, b, c;
        Console.Write("enter values of a : ");
        a = Convert.ToInt32(Console.ReadLine());
        Console.Write("enter values of b : ");
        b = Convert.ToInt32(Console.ReadLine());
        Console.Write("enter values of c : ");
        c = Convert.ToInt32(Console.ReadLine());
        b b1 = new b();
        Console.WriteLine(b1.getdata(a,b,c));
        Console.Read();
    }
}
//Write a program to create an abstract class find Rectangle class area.
using System;
abstract class abs
{
    public abstract void area(Double l,Double w);
}
class getdata : abs
{
    public override void area(Double l, Double w)
    {
        double area;
        area = l * w;
        Console.WriteLine("Rectangle area is : {0} ",area);

    }
}

class myclass
{
    public static void Main()
    {
        Double l, w;
        Console.WriteLine("enter length");
        l = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("enter width");
        w= Convert.ToDouble(Console.ReadLine());
        getdata d = new getdata();
        d.area(l, w);
        Console.Read();
    }
}
//Write a program to calculate simple interest using multilevel inheritance.
using System;
class a
{
    public int pi, rate, year, amt, tot;
    public void getdata(int p, int r, int n)
    {
        pi = p;
        rate = r;
        year = n;
      
    }
}
class b : a
{
    public void logic()
    {
        amt = pi * rate * year / 100;
        tot = pi + amt;
        Console.WriteLine("Simple Intrest{0}", tot);
    }
}
class myclass
{
    public static void Main()
    {
        int p, r, n;
        Console.WriteLine("enter principle amount");
        p = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("enter intrest");
        r = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("enter year");
        n = Convert.ToInt32(Console.ReadLine());
        b b1 = new b();
        b1.getdata(p, r, n);
         b1.logic();
        Console.Read();
    }
}

Tuesday, 3 March 2015

//C# Program to Calculate Power of Three
using System;
class Program
    {
        static void Main(string[] args)
        {
        new GeneratePowers().RaiseToPower(5, 3);
            Console.ReadLine();// power to raise each value
        }
    }
   
    public class GeneratePowers
    {
        public void RaiseToPower(int maxIterations, int power)
        {
            Console.WriteLine("{0,8}{1,16}",
                "Number", "Power of " + power);
            for (int i = 1; i <= maxIterations; ++i)
            {
                Console.Write("{0,5}{1,15}\n", i,
                   Math.Pow(i, power));
            }
        }
     }
//C# Program to Print a BinaryTriangle
using System;
        class myclass
        {
            public static void Main()
            {
                int input;
                Console.WriteLine("Enter the Number of Rows : ");
                  input = int.Parse(Console.ReadLine());
                  demo d = new demo();
                  d.getvalue(input);
                Console.Read();
            }
        }
        class demo
        {
            public void getvalue(int value)
            {
                int p, lastInt = 0;
                for (int i = 1; i <= value; i++)
                {
                    for (p = 1; p <= i; p++)
                    {
                        if (lastInt == 1)
                        {
                            Console.Write("0");
                            lastInt = 0;
                        }
                        else if (lastInt == 0)
                        {
                            Console.Write("1");
                            lastInt = 1;
                        }
                    }
                    Console.Write("\n");
                }
            }
        }
// C# Program User Define Jagged Array
using System;
class Program
{
    public static void Main()
    {
      
            int getele;
            Console.Write("Enter Array Length :");
            int value = Convert.ToInt32(Console.ReadLine());
            string[][] arr = new string[value][];
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write("Enter arr[" + i + "] Length:");
                getele = Convert.ToInt32(Console.ReadLine());
                arr[i] = new string[getele];

            }
            Console.WriteLine("--------------------------------");
            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = 0; j < arr[i].Length; j++)
                {
                    Console.Write("Enter Value arr[" + i + "][" + j + "] Element:");
                    arr[i][j] = Console.ReadLine();
                }
                Console.WriteLine("--------------------------------");
            }
            Console.WriteLine("-------- Array Values --------\n\n");
            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = 0; j < arr[i].Length; j++)
                {
                    Console.WriteLine("Value is :{0}",arr[i][j]);
                }
                Console.WriteLine("---------------");
            }
        Console.Read();
    }
}
//C# Program to Check Whether the Entered Year is a Leap Year or Not
using System;
class myclass
{
    public static void Main()
    {
        int y;
        Console.WriteLine("Enter the Year in Four Digits : ");
        y = Convert.ToInt32(Console.ReadLine());
        leapyear obj = new leapyear();
        obj.leap(y);
       Console.Read();
    }
}
class leapyear
{
    public void leap(int y)
    {
        if ((y % 4 == 0))
        {
            Console.WriteLine("{0} is a Leap Year", y);
        }
        else
        {
            Console.WriteLine("{0} is not a Leap Year", y);
        }
   }
}