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);
        }
   }
}
//Write a program to calculate compound interest.
using System;
class a
{
        public void interest(double p ,double r,double n ,double t)
        {
                double tot=0;
               for(int i=1;i<t+1;i++)
               {
                        tot=p*Math.Pow((1+r/n),(n*i));
                        Console.WriteLine("your total for year {0} "+" is {1:F0}",i,tot);
               }
        }
}
class my
{
        public static void Main()
        {
                Double p,r,n,t;
                Console.Write("Enter Pricipal Amount:");
                p=Convert.ToDouble(Console.ReadLine());
                Console.Write("Enter Rate:");
                r=Convert.ToDouble(Console.ReadLine())/100;
                Console.Write("No of year:");
                n=Convert.ToDouble(Console.ReadLine());
                Console.Write("No of years");
                t=Convert.ToDouble(Console.ReadLine());
                a a1= new a();
                a1.interest(p,r,n,t);
                Console.Read();
        }
}
//Write a program check whether the Entered Number is Prime Number or Not.
using System;
class a
{
    public void getdata(int num)
    {
        int k;
        k = 0;
        for (int i = 1; i <= num; i++)
        {
            if (num % i == 0)
            {
                k++;
            }
        }
        if (k == 2)
        {
            Console.WriteLine("Entered Number is a Prime Number and the Largest Factor is {0}", num);
        }
        else
        {
            Console.WriteLine("Not a Prime Number");
        }
    }
}
class myclass
{
    public static void Main()
    {
        int num;
        Console.WriteLine("enter number");
        num = Convert.ToInt32(Console.ReadLine());
        a a1 = new a();
        a1.getdata(num);
       Console.Read();
    }
}
//C# Program to Reverse a Number & Check if it is a Palindrome
   
    using System;
    class program
    {
        public static void Main()
        {
            int num;
       
            Console.WriteLine("Enter an integer \n");
            num = Convert.ToInt32(Console.ReadLine());
            palindrome p = new palindrome();
            p.data(num);
            Console.Read();
        }
    }
    class palindrome
    {
        public void data(int num)
        {
            int temp, remainder, reverse = 0;
            temp = num;
            while (num > 0)
            {
                remainder = num % 10;
                reverse = reverse * 10 + remainder;
                num = num / 10;
            }
            Console.WriteLine("Given number is = {0}", temp);
            Console.WriteLine("Its reverse is  = {0}", reverse);
            if (temp == reverse)
                Console.WriteLine("Number is a palindrome \n");
            else
                Console.WriteLine("Number is not a palindrome \n");
        }
    }
//Write a program to calculate the distance travelled by reading speed and time.
using System;
class program
{
    public static void Main()
    {
        int speed, time;
        Console.WriteLine("Enter the Speed : ");
        speed = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter the Time : ");
        time = Convert.ToInt32(Console.ReadLine());
        dist d = new dist();
        d.distance(speed, time);
        Console.Read();
    }
}
class dist
{
    public void distance(int speed,int time)
    {
        int distance;
        distance = speed * time;
        Console.WriteLine("Distance Travelled : " + distance);
    }
}

Monday, 2 March 2015

// C# Program to Get a Number and Display the Sum of the Digits
    using System;
    class Program
        {
           public static void Main()
            {
                int num;
                Console.WriteLine("Enter a Number : ");
                num = Convert.ToInt32(Console.ReadLine());
                sum s = new sum();
                s.get(num);
            }
        }
        class sum
        {
            public void get(int num)
            {
                int sum = 0, r;
                while (num != 0)
                {
                    r = num % 10;
                    num = num / 10;
                    sum = sum + r;
                }
                Console.WriteLine("Sum of Digits of the Number : " + sum);
                Console.ReadLine();
            }
        }
//Write a program to generate the Factorial of a Given Number.
using System;
class a
{
        public void getdata(int n)
        {
                int i;
                int fact=1;
                i=1;
                while(i<=n)
                {
                        fact=fact*i;
                        i++;
                }
                Console.WriteLine(fact);
        }
}
class b
{
        public static void Main()
        {
            int n;
            Console.WriteLine("enter number");
            n = Convert.ToInt32(Console.ReadLine());
                a a1=new a();
                a1.getdata(n);
                Console.Read();
        }
}
// C#  Program to Generate Fibonacci Series
    using System;
       class Program
        {
           public static void Main()
            {
                int count;
                Console.Write("Enter the Limit : ");
                count = Convert.ToInt32(Console.ReadLine());
                fib f = new fib();
                f.get(count);
                Console.Read();
            }
        }
        class fib
        {
            public void get(int count)
            {
                int i, f1 = 0, f2 = 1, f3 = 0;
                Console.WriteLine(f1);
                Console.WriteLine(f2);
                for (i = 0; i <= count; i++)
                {
                    f3 = f1 + f2;
                    Console.WriteLine(f3);
                    f1 = f2;
                    f2 = f3;
                }
            }
       }

// C# Program to Perform all Basic Arithmetic Operations using interface
using System;
interface myinterface
{
    void addition(int a,int b);
    void multiplication(int a, int b);
    void division(int a, int b);
    void substraction(int a, int b);
}
class a : myinterface
{
    public void addition(int a,int b)
    {
        int result;
        result = a + b;
        Console.WriteLine("addition is : {0}",result);
       
    }
    public void multiplication(int a, int b)
    {
        int result;
        result = a * b;
        Console.WriteLine("multiplication is : {0}",result);
       
    }
    public void division(int a, int b)
    {
        int result;
        result = a / b;
        Console.WriteLine("division is : {0}",result);
       
    }
    public void substraction(int a, int b)
    {
        int result;
        result = a - b;
        Console.WriteLine("substraction is : {0}",result);
       
    }
}
class program
{
        public static void Main()
        {
            int a,b;
            String option;
            Console.WriteLine("enter value");
            a=Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("enter value");
            b=Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("1.Addition");
            Console.WriteLine("2.multiplicaition");
            Console.WriteLine("3.divition");
            Console.WriteLine("4.subtraction");
            option =(Console.ReadLine());
              a a1 = new a();
            switch(option)
            {
                case"1":
                  a1.addition(a,b);
                break;
                case "2":
                a1.multiplication(a, b);
                break;
                case "3":
                a1.division(a, b);
                break;
                case "4":
                a1.substraction(a, b);
                break;
                 default:
                Console.WriteLine("invalid option");
                break;
        }
        Console.Read();
    }
}
 // C# Program to Check Whether the Entered Number is an Armstrong Number or Not
  using System;
  class Program
        {
           public static void Main()
            {
                int number;
                Console.Write("enter the Number : ");
                number = Convert.ToInt32(Console.ReadLine());
                ams a = new ams();
                a.getvalue(number);
                Console.Read();

            }
         }
    class ams
    {
        public void getvalue(int number)
        {

            int  remainder, sum = 0;
            for (int i = number; i > 0; i = i / 10)
            {
                remainder = i % 10;
                sum = sum + remainder * remainder * remainder;
            }
            if (sum == number)
            {
                Console.Write("Entered Number is an Armstrong Number");
            }
            else
            {
                Console.Write("Entered Number is not an Armstrong Number");
            }
        }

    }