Sunday, June 24, 2012

program for finding mark sheet individual subject marks ,total and average using set and get


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

namespace r_w_property
{
    class marksheet
    {
        private int math;
        private int phy;
        private int che;
        private int eng;
        public int math_marks
        {
            get
            {
                return math;
            }
            set
            {
                math = value;
            }
        }
        public int phy_marks
        {
            get
            {
                return phy;
            }
            set
            {
                phy = value;
            }
        }
        public int eng_marks
        {
            get
            {
                return eng;
            }
            set
            {
                eng = value;
            }
        }
        public int che_marks
        {
            get
            {
                return che;
            }
            set
            {
                che = value;
            }
        }
       
    }
    class Program
    {
        static void Main(string[] args)
        {
            marksheet m= new marksheet();
            m.math_marks=45;
            m.phy_marks=46;
            m.che_marks=47;
            m.eng_marks=43;
            Console.WriteLine
            (
            @"student individual subject marks:
math marks={0}
phy marks={1}
che marks={2}
eng marks={3} ",m.math_marks,
            m.phy_marks,
            m.che_marks,
            m.eng_marks);
            int total = m.math_marks + m.phy_marks + m.che_marks + m.eng_marks;
            Console.WriteLine("total marks is:"+total);
            float avg = total / 4;
            Console.WriteLine("Avrage marks is:"+avg);
            Console.ReadKey();

        }
    }
}

output



student individual subject marks:
math marks=45
phy marks=46
che marks=47
eng marks=43
total marks is:181
Avrage marks is:45



Saturday, June 23, 2012

create class library and call it in basic program in c#

Go on File -- New -- Project -- choose Class library --  Give your library name--ok


using System;

namespace library
{
    public class lib
    {
        static public int sum(int a, int b)
        {
            return (a + b);
        }
    }
}

  • Then compile it


Now call it in basic program :

Go on File -- New -- Project -- choose Console Application -- Give your   Console Application _name--ok

For setting
Go on Project -- Add Reference -- Browse -- choose location where Console Application save -- bin-- Debug--  library_name.dll

using System;

namespace class_sum_library
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            Console.WriteLine("Enter number for a:");
            a = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter number for b:");
            b = int.Parse(Console.ReadLine());
            c = a + b;
            library.lib.sum(a, b);
            Console.WriteLine("Sum is:" + c);
            Console.ReadKey();
            
        }

    }
}

output



Enter number for a:
400
Enter number for b:
234
Sum is:634

how to impement interface in c#


using System;

    interface pnr
    {

        void pnr();
     
    }
    interface si : pnr
    {
        void simple_intrest();
    }



    class result : si
    {
        static void Main(string[] args)
        {

            result s = new result();

            s.pnr();
            s.simple_intrest();
            Console.ReadKey();

        }


        public void simple_intrest()
        {
            int p, n, r;
            Console.WriteLine("\nEnter value for principle amount");
            p = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter value for rate");
            r = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter value for time");
            n = int.Parse(Console.ReadLine());
            int si = p * n * r / 100;
            Console.WriteLine("Simple interest is:{0} for principle amount is:{1}", si, p);
        }
        public void pnr()
        {
            Console.WriteLine("Enter the value for p,n,r");


        }

    }
Output

Enter the value for p,n,r

Enter value for principle amount
20000
Enter value for rate
5
Enter value for time
4
Simple intrest is:4000 for principle amount is:20000

Thursday, June 21, 2012

inheritance program in c#


using System;

namespace inhetance
{
    class cal
    {
        public int a, b, c;
        public int sum(int x, int y)
        {
            a = x;
            b = y;
            c = a + b;
            return (c);
        }
        public int sub(int x, int y)
        {
            a = x;
            b = y;
            c = a - b;
            return (c);
        }
        public int div(int x, int y)
        {
            a = x;
            b = y;
            c = a / b;
            return (c);
        }
        public int mul(int x, int y)
        {
            a = x;
            b = y;
            c = a * b;
            return (c);
        }
    }


       class scal : cal
       {
           public void factorial(int n)
           {
               int i,fact = 1;
             
             
               for (i = n; i >= 1; i--)
               {
                   fact = fact * i;
               }
               Console.WriteLine("factorial value of n is:" +fact);
           }
       }
 
    class Program
    {
        static void Main(string[] args)
        {
            cal x = new cal();
            int a, b,c;
            Console.WriteLine("Enter the number for a & b=:");
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());
            x.sum(a, b);
            x.sum(a,b);
            x.mul(a, b);
            x.div(a, b);
            Console.WriteLine("sum of a & b is"+x.sum(a,b));
            Console.WriteLine("sum of a & b is" + x.sub(a, b));
            Console.WriteLine("sum of a & b is" + x.mul(a, b));
            Console.WriteLine("sum of a & b is" + x.div(a, b));
         
            scal x1 = new scal();
            int n;
            Console.WriteLine("Enter no for factorial value:");
            n = int.Parse(Console.ReadLine());
            x1.factorial(n);
         
            Console.ReadKey();

        }
    }
}


Output:


Enter the number for a & b=:
12
3
sum of a & b is15
sum of a & b is9
sum of a & b is36
sum of a & b is4
Enter no for factorial value:
7
factorial value of n is:5040

find simple interest c#


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

namespace intrest
{
    class si
    {
        public int p, n, r;
         public int getdata(int x, int y, int z)
        {
            int b;
            p = x;
            n = y;
            r = z;
             b= p * n * r / 100;
             return(b);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int a, b,c;
            si i = new si();
         
            Console.WriteLine("Enter principal amount:");
            a = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter rate:");
            b = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter time in year:");
            c = int.Parse(Console.ReadLine());

            int simple_intrest = i.getdata(a,b,c);
            Console.WriteLine("simple intrest={0} of principal={1}", simple_intrest,a);
            Console.ReadKey();

        }
    }

}

Output

Enter principal amount:
20000
Enter rate:
5
Enter time in year:
4
simple intrest=4000 of principal=20000



Tuesday, June 19, 2012

fibonacci series in c#


using System;

namespace fibonic
{
    class Program
    {
        static void Main(string[] args)
        {
            int a=0, b=1,n, c, i;
            Console.WriteLine("Enter no for fibonic series");
            n = int.Parse(Console.ReadLine());
            Console.WriteLine("Fibonic series is:");
            Console.WriteLine(""+a);
            Console.WriteLine("" +b);
         
            for (i = 1; i <= n; i++)
            {
                c= a + b;
                a= b;
                b = c;
                Console.WriteLine("" + c);
           

            }
            Console.ReadKey();
         
        }
    }
}

Output
Enter no for fibonic series
6
Fibonic series is:
0
1
1
2
3
5
8
13

printing 1 12 123 1234 12345 in triangle in c#


using System;


namespace counting
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j;
            for (i = 1; i <= 5; i++)
             
            {
                for (j =1; j <= i; j++)
                {
                    Console.Write(""+(j));

                }
                Console.WriteLine("");

            }
            Console.ReadKey();
        }
    }
}

Output:
1
12
123
1234
12345




//giving range

using System;


namespace count_increment
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            Console.WriteLine("Enter no for range");
            n = int.Parse(Console.ReadLine());
            int i, j;
            for (i = 1; i <=n; i++)
         
            {
                for (j = 1; j <= i; j++)
                {
                   
                    Console.Write(""+j);
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output:


Enter no for range
6
1
12
123
1234
12345
123456



printing 1 23 456 in triangle in c#


using System;


namespace count_increment
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j, count = 0;
            for (i = 0; i <3; i++)
         
            {
                for (j = 0; j <= i; j++)
                {
                    count++;
                    Console.Write(""+count);
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}


Output
1
23
456



//giving range

using System;


namespace count_increment
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            Console.WriteLine("Enter no for range");
            n = int.Parse(Console.ReadLine());
            int i, j, count = 0;
            for (i = 1; i <=n; i++)
           
            {
                for (j = 1; j <= i; j++)
                {
                    count++;
                    Console.Write(""+count);
                }
                Console.WriteLine("");
            }
            Console.ReadKey();
        }
    }
}

Output

Enter no for range
5
1
23
456
78910
1112131415