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");
        }
    }