1.
Calculate and Display BMI
csharp
Copy code
using System;
class Program
    static void Main()
        Console.Write("Enter weight in kilograms: ");
        double weight = Convert.ToDouble(Console.ReadLine());
        Console.Write("Enter height in meters: ");
        double height = Convert.ToDouble(Console.ReadLine());
        double bmi = weight / (height * height);
        Console.WriteLine($"Your BMI is: {bmi:F2}");
2. Convert and Display Temperature
csharp
Copy code
using System;
class Program
    static void Main()
        Console.Write("Enter temperature value: ");
        double value = Convert.ToDouble(Console.ReadLine());
        Console.Write("Enter temperature unit (C/F/K): ");
        char unit = Console.ReadKey().KeyChar;
        Console.WriteLine();
        switch (unit)
            case 'C':
              Console.WriteLine($"Temperature in Fahrenheit: {(value * 9 / 5) + 32}");
              Console.WriteLine($"Temperature in Kelvin: {value + 273.15}");
              break;
            case 'F':
              Console.WriteLine($"Temperature in Celsius: {(value - 32) * 5 / 9}");
              Console.WriteLine($"Temperature in Kelvin: {(value - 32) * 5 / 9 + 273.15}");
              break;
            case 'K':
              Console.WriteLine($"Temperature in Celsius: {value - 273.15}");
              Console.WriteLine($"Temperature in Fahrenheit: {(value - 273.15) * 9 / 5 + 32}");
              break;
            default:
              Console.WriteLine("Invalid unit.");
              break;
3. Calculate and Display Hypotenuse
csharp
Copy code
using System;
class Program
{
    static void Main()
        Console.Write("Enter the length of side a: ");
        double a = Convert.ToDouble(Console.ReadLine());
        Console.Write("Enter the length of side b: ");
        double b = Convert.ToDouble(Console.ReadLine());
        double hypotenuse = Math.Sqrt(a * a + b * b);
        Console.WriteLine($"The length of the hypotenuse is: {hypotenuse:F2}");
4. Calculate and Display Compound Interest
csharp
Copy code
using System;
class Program
    static void Main()
        Console.Write("Enter principal amount: ");
        double principal = Convert.ToDouble(Console.ReadLine());
        Console.Write("Enter annual interest rate (in percentage): ");
        double rate = Convert.ToDouble(Console.ReadLine()) / 100;
        Console.Write("Enter number of times interest is compounded per year: ");
        int n = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter time period in years: ");
        double time = Convert.ToDouble(Console.ReadLine());
        double amount = principal * Math.Pow(1 + rate / n, n * time);
        Console.WriteLine($"The compound interest is: {amount - principal:F2}");
5. Find the Largest Element in a Matrix
csharp
Copy code
using System;
class Program
    static void Main()
        Console.Write("Enter number of rows: ");
        int rows = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter number of columns: ");
        int cols = Convert.ToInt32(Console.ReadLine());
        int[,] matrix = new int[rows, cols];
        Console.WriteLine("Enter the matrix elements:");
        for (int i = 0; i < rows; i++)
            for (int j = 0; j < cols; j++)
                matrix[i, j] = Convert.ToInt32(Console.ReadLine());
        }
        int largest = matrix[0, 0];
        for (int i = 0; i < rows; i++)
            for (int j = 0; j < cols; j++)
                if (matrix[i, j] > largest)
                    largest = matrix[i, j];
        Console.WriteLine($"The largest element in the matrix is: {largest}");
6. Multiply Two Matrices
csharp
Copy code
using System;
class Program
    static void Main()
        Console.Write("Enter number of rows for matrix A: ");
        int aRows = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter number of columns for matrix A (and rows for matrix B): ");
        int aCols = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter number of columns for matrix B: ");
int bCols = Convert.ToInt32(Console.ReadLine());
int[,] matrixA = new int[aRows, aCols];
int[,] matrixB = new int[aCols, bCols];
Console.WriteLine("Enter matrix A elements:");
for (int i = 0; i < aRows; i++)
    for (int j = 0; j < aCols; j++)
        matrixA[i, j] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter matrix B elements:");
for (int i = 0; i < aCols; i++)
    for (int j = 0; j < bCols; j++)
        matrixB[i, j] = Convert.ToInt32(Console.ReadLine());
int[,] result = new int[aRows, bCols];
for (int i = 0; i < aRows; i++)
    for (int j = 0; j < bCols; j++)
        for (int k = 0; k < aCols; k++)
            result[i, j] += matrixA[i, k] * matrixB[k, j];
                }
        Console.WriteLine("Resultant Matrix:");
        for (int i = 0; i < aRows; i++)
            for (int j = 0; j < bCols; j++)
                Console.Write(result[i, j] + " ");
            Console.WriteLine();
7. Find the Average of All Array Elements
csharp
Copy code
using System;
class Program
    static void Main()
        Console.Write("Enter the number of elements: ");
        int n = Convert.ToInt32(Console.ReadLine());
        double[] array = new double[n];
        double sum = 0;
        Console.WriteLine("Enter the elements:");
        for (int i = 0; i < n; i++)
            array[i] = Convert.ToDouble(Console.ReadLine());
            sum += array[i];
        double average = sum / n;
        Console.WriteLine($"The average is: {average:F2}");
8. Reverse a String Without Using Reverse Function
csharp
Copy code
using System;
class Program
    static void Main()
        Console.Write("Enter a string: ");
        string input = Console.ReadLine();
        char[] array = input.ToCharArray();
        Array.Reverse(array);
        Console.WriteLine($"Reversed string: {new string(array)}");
9. Find the Frequency of the Word "is"
csharp
Copy code
using System;
class Program
    static void Main()
        string sentence = "All that is, is, and that is all there is.";
        string[] words = sentence.Split(new[] { ' ', ',', '.' }, StringSplitOptions.RemoveEmptyEntries);
        int count = 0;
        foreach (var word in words)
            if (word.Equals("is", StringComparison.OrdinalIgnoreCase))
                count++;
        Console.WriteLine($"The word 'is' appears {count} times.");
10. Demonstrate Multilevel Inheritance
csharp
Copy code
using System;
class Grandparent
    public void GrandparentMethod()
        Console.WriteLine("Grandparent method");
}
class Parent : Grandparent
    public void ParentMethod()
        Console.WriteLine("Parent method");
class Child : Parent
    public void ChildMethod()
        Console.WriteLine("Child method");
class Program
    static void Main()
        Child child = new Child();
        child.GrandparentMethod();
        child.ParentMethod();
        child.ChildMethod();
11. Find All Even Numbers in a List Using Lambda Expression
csharp
Copy code
using System;
using System.Collections.Generic;
using System.Linq;
class Program
    static void Main()
        List<int> numbers = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        var evenNumbers = numbers.Where(n => n % 2 == 0).ToList();
        Console.WriteLine("Even numbers:");
        evenNumbers.ForEach(n => Console.WriteLine(n));