C# Program - Implementation of multi-level inheritance | Area of a rectangle | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        public class data
        {
            public int l, b;
            public void getdata()
            {
                Console.Write("Enter length and breadth");
                l = int.Parse(Console.ReadLine());
                b = int.Parse(Console.ReadLine());
            }
        }
        public class area:data
        {
            public int ar;
            public void area1()
            {
                ar = l * b;
            }
        }
        public class perimeter : area
        {
            public int peri;
            public void peri1()
            {
                peri = 2*(l + b);
            }
            public void showdata()
            {
                Console.Write("The area is:" + ar);
                Console.Write("The perimeter is:"+peri);
            }
        }
        static void Main(string[] args)
        {
            perimeter p = new perimeter();
            p.getdata();
            p.area1();
            p.peri1();
            p.showdata();
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Implementation of default constructor | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        public class student
        {
            public int a, b;
            public student()
            {
                a = 0;
                b = 0;
            }
            public void showdata()
            {
                Console.Write("a=" + a);
                Console.Write("b=" + b);
            }
        }
        static void Main(string[] args)
        {
            student s1 = new student();
            s1.showdata();
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Implementation of parameterized constructor | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        public class student
        {
            public int a, b;
            public student(int x, int y)
            {
                a = x;
                b = y;
            }
            public void showdata()
            {
                Console.Write("a=" + a);
                Console.Write("b=" + b);
            }
        }
        static void Main(string[] args)
        {
            student s1 = new student(2,3);
            s1.showdata();
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Implementation of copy constructor | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        public class student
        {
            public int a, b;
            public student(int x, int y)
            {
                a = x;
                b = y;
            }
            public student(student n)
            {
                a = n.a;
                b = n.b;
            }
            public void showdata()
            {
                Console.Write("a=" + a);
                Console.Write("b=" + b);
            }
        }
        static void Main(string[] args)
        {
            student s1 = new student(2,3);
            student s2 = new student(s1);
            s1.showdata();
            s2.showdata();
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Implementation of single inheritance | Area of a circle | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        public class circle
        {
            public double r;
            public void getdata()
            {
                Console.Write("Enter the radius");
                r = int.Parse(Console.ReadLine());
            }
        }
        public class area:circle
        {
            public double ar;
            public void area1()
            {
                ar = 3.14 * r * r;
            }
            public void showdata()
            {
                Console.Write("The area of the circle is:" + ar);
            }
        }
        static void Main(string[] args)
        {
            area a = new area();
            a.getdata();
            a.area1();
            a.showdata();
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Sum of the digits of a number | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n,sum=0,temp;
            Console.Write("Enter the number");
            n = int.Parse(Console.ReadLine());
            while (n != 0)
            {
                temp = n % 10;
                sum = sum + temp;
                n = n / 10;
            }
            Console.Write("The sum of the digits is:"+sum);
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Check the type of triangle | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,b,c;
            Console.Write("Enter 3 side of the triangle");
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());
            c = int.Parse(Console.ReadLine());
            if (a == b && b == c)
                Console.Write("The triangle is equilateral");
            else if (a != b && b != c)
                Console.Write("The triangle is scalene");
            else
                Console.Write("The triangle is issocelles");
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Check whether a number is odd or even | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            Console.Write("Enter a number");
            n = int.Parse(Console.ReadLine());
            if(n%2==0)
            Console.Write("The of the numbers is even");
            else
            Console.Write("The of the numbers is odd");
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Check whether a number is positive or negative | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            Console.Write("Enter a number");
            n = int.Parse(Console.ReadLine());
            if(n<0)
            Console.Write("The of the numbers is negative");
            else
            Console.Write("The of the numbers is positive");
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Sum of n numbers | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i=1,n,sum=0;
            Console.Write("Enter a number");
            n = int.Parse(Console.ReadLine());
            while(i<=n)
            {
                sum = sum + i;
                i++;
            }
            Console.Write("The of the numbers is:" + sum);
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Reverse of a number | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, rev=0, temp;
            Console.Write("Enter a number");
            n = int.Parse(Console.ReadLine());
            while(n!=0)
            {
                temp = n % 10;
                rev = rev * 10 + temp;
                n = n / 10;
            }
            Console.Write("The reverse of the number is:" + rev);
            Console.ReadKey();
        }
    }
}

/* Do leave a comment if you find this useful*/

C# Program - Check whether a number is prime or not | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, n,flag = 0;
            Console.Write("Enter a number");
            n = int.Parse(Console.ReadLine());
            for(i=1;i<=n;i++)
            {
                if (i % 2 == 0)
                    flag++;
            }
            if(flag==2)
            Console.Write("The number is Prime");
            else
            Console.Write("The number is not Prime");
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Check whether a number is palindrome or not | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, temp, rev=0, pal;
            Console.Write("Enter a number");
            n = int.Parse(Console.ReadLine());
            pal = n;
            do
            {
                temp = n % 10;
                rev = rev * 10 + temp;
                n = n / 10;
            } while (n!=0);
            if(rev==pal)
            Console.Write("The number is Palindrome");
            else
            Console.Write("The number is not Palindrome");
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/

C# Program - Fibonacci Series | Digital Infotainment

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a=0, b=1, c, n;
            Console.Write("Enter a number");
            n = int.Parse(Console.ReadLine());
            Console.Write("The fibonacci series of the number is:");
            Console.Write(" "+a);
            Console.Write(" "+b);
            c=a+b;
            do
            {
                Console.Write(" " + c);
                a = b;
                b = c;
                c = a + b;
            } while (c <= n);
            Console.ReadKey();
        }
    }
}

/*Do leave a comment if you find this useful*/