This is Not AD.
Join Our Telegram Channel To Get OUR all Material Up to Date.
Don't Worry Your All Info Will Be Secured
Home About Us Services Materials Contact Us
Home About Services Materials Contact
‹
›
Home
Home > C# | SU [ 21 - 30 ] [ FOR JOURNAL ]
CODE

using System;

class MergeArrays
{
    static void Main()
    {
        int[] arr1 = { 1, 3, 5 };
        int[] arr2 = { 2, 4, 6 };
        int[] merged = new int[arr1.Length + arr2.Length];

        for (int i = 0; i < arr1.Length; i++)
        {
            merged[i] = arr1[i];
        }

        for (int i = 0; i < arr2.Length; i++)
        {
            merged[arr1.Length + i] = arr2[i];
        }

        Console.Write("Merged Array: ");
        for (int i = 0; i < merged.Length; i++)
        {
            Console.Write(merged[i] + " ");
        }
    }
}
                
OUTPUT

Merged Array: 1 3 5 2 4 6
                    
CODE

using System;

class RemoveDuplicates
{
    static void Main()
    {
        int[] arr = { 1, 2, 2, 3, 4, 4, 5 };
        int n = arr.Length;
        int[] temp = new int[n];
        int j = 0;

        for (int i = 0; i < n - 1; i++)
        {
            if (arr[i] != arr[i + 1])
            {
                temp[j++] = arr[i];
            }
        }
        temp[j++] = arr[n - 1];

        Console.Write("After removing duplicates: ");
        for (int i = 0; i < j; i++)
        {
            Console.Write(temp[i] + " ");
        }
    }
}
                
OUTPUT

After removing duplicates: 1 2 3 4 5
                    
CODE

using System;

class SecondLargest
{
    static void Main()
    {
        int[] arr = { 12, 35, 1, 10, 34, 1 };
        int first = int.MinValue;
        int second = int.MinValue;

        for (int i = 0; i < arr.Length; i++)
        {
            if (arr[i] > first)
            {
                second = first;
                first = arr[i];
            }
            else if (arr[i] > second && arr[i] != first)
            {
                second = arr[i];
            }
        }

        Console.WriteLine("Second Largest Element: " + second);
    }
}
                
OUTPUT

Second Largest Element: 34
                    
CODE

using System;

class JaggedArray
{
    static void Main()
    {
        int[][] jagged = new int[3][];
        jagged[0] = new int[] { 80, 90 };
        jagged[1] = new int[] { 70, 60, 85 };
        jagged[2] = new int[] { 50, 55, 60, 65 };

        for (int i = 0; i < jagged.Length; i++)
        {
            int sum = 0;
            for (int j = 0; j < jagged[i].Length; j++)
            {
                sum += jagged[i][j];
            }
            double avg = (double)sum / jagged[i].Length;
            Console.WriteLine("Average for Student " + (i + 1) + ": " + avg);
        }
    }
}
                
OUTPUT

Average for Student 1: 85
Average for Student 2: 71.6666666666667
Average for Student 3: 57.5
                    
CODE

using System;

class BubbleSort
{
    static void Main()
    {
        int[] arr = { 64, 34, 25, 12, 22, 11, 90 };
        int n = arr.Length;

        for (int i = 0; i < n - 1; i++)
        {
            for (int j = 0; j < n - i - 1; j++)
            {
                if (arr[j] > arr[j + 1])
                {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }

        Console.Write("Sorted Array: ");
        for (int i = 0; i < n; i++)
        {
            Console.Write(arr[i] + " ");
        }
    }
}
                
OUTPUT

Sorted Array: 11 12 22 25 34 64 90
                    
CODE

using System;

class SelectionSort
{
    static void Main()
    {
        int[] arr = { 64, 25, 12, 22, 11 };
        int n = arr.Length;

        for (int i = 0; i < n - 1; i++)
        {
            int min_idx = i;
            for (int j = i + 1; j < n; j++)
            {
                if (arr[j] < arr[min_idx])
                {
                    min_idx = j;
                }
            }

            int temp = arr[min_idx];
            arr[min_idx] = arr[i];
            arr[i] = temp;
        }

        Console.Write("Sorted Array: ");
        for (int i = 0; i < n; i++)
        {
            Console.Write(arr[i] + " ");
        }
    }
}
                
OUTPUT

Sorted Array: 11 12 22 25 64

                    
CODE

using System;

class ConditionalMax
{
    static void Main()
    {
        Console.Write("Enter first number: ");
        int a = Convert.ToInt32(Console.ReadLine());

        Console.Write("Enter second number: ");
        int b = Convert.ToInt32(Console.ReadLine());

        int max = (a > b) ? a : b;

        Console.WriteLine("Maximum number is: " + max);
    }
}

                
OUTPUT

Enter first number: 10
Enter second number: 20
Maximum number is: 20

                    
CODE

using System;

class NestedSwitch
{
    static void Main()
    {
        Console.WriteLine("1. File");
        Console.WriteLine("2. Edit");
        Console.Write("Enter choice: ");
        int mainChoice = Convert.ToInt32(Console.ReadLine());

        switch (mainChoice)
        {
            case 1:
                Console.WriteLine("1. New");
                Console.WriteLine("2. Open");
                Console.Write("Enter File choice: ");
                int fileChoice = Convert.ToInt32(Console.ReadLine());
                switch (fileChoice)
                {
                    case 1: Console.WriteLine("New File Created"); break;
                    case 2: Console.WriteLine("File Opened"); break;
                    default: Console.WriteLine("Invalid File Option"); break;
                }
                break;
            case 2:
                Console.WriteLine("1. Cut");
                Console.WriteLine("2. Copy");
                Console.Write("Enter Edit choice: ");
                int editChoice = Convert.ToInt32(Console.ReadLine());
                switch (editChoice)
                {
                    case 1: Console.WriteLine("Cut Performed"); break;
                    case 2: Console.WriteLine("Copy Performed"); break;
                    default: Console.WriteLine("Invalid Edit Option"); break;
                }
                break;
            default:
                Console.WriteLine("Invalid Main Option");
                break;
        }
    }
}
                
OUTPUT

1. File
2. Edit
Enter choice: 1
1. New
2. Open
Enter File choice: 2
File Opened
                    
CODE

using System;

class SimpleCalculator
{
    static void Main()
    {
        while (true)
        {
            Console.Write("Enter first number: ");
            double num1 = Convert.ToDouble(Console.ReadLine());

            Console.Write("Enter operator (+, -, *, /) or 'x' to exit: ");
            char op = Convert.ToChar(Console.ReadLine());
            
            if (op == 'x') break;

            Console.Write("Enter second number: ");
            double num2 = Convert.ToDouble(Console.ReadLine());

            switch (op)
            {
                case '+': Console.WriteLine("Result: " + (num1 + num2)); break;
                case '-': Console.WriteLine("Result: " + (num1 - num2)); break;
                case '*': Console.WriteLine("Result: " + (num1 * num2)); break;
                case '/': Console.WriteLine("Result: " + (num1 / num2)); break;
                default: Console.WriteLine("Invalid Operator"); break;
            }
            Console.WriteLine();
        }
    }
}
                
OUTPUT

Enter first number: 10
Enter operator (+, -, *, /) or 'x' to exit: *
Enter second number: 5
Result: 50

Enter first number: 20
Enter operator (+, -, *, /) or 'x' to exit: x

                    
CODE

using System;

class LeapYear
{
    static void Main()
    {
        Console.Write("Enter Year: ");
        int year = Convert.ToInt32(Console.ReadLine());

        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
        {
            Console.WriteLine(year + " is a Leap Year");
        }
        else
        {
            Console.WriteLine(year + " is not a Leap Year");
        }
    }
}
                
OUTPUT

Enter Year: 2024
2024 is a Leap Year
                    

No comments:

Post a Comment

Friday, 30 January 2026

C# | SU [ 21 - 30 ] [ FOR JOURNAL ]

CODE

using System;

class MergeArrays
{
    static void Main()
    {
        int[] arr1 = { 1, 3, 5 };
        int[] arr2 = { 2, 4, 6 };
        int[] merged = new int[arr1.Length + arr2.Length];

        for (int i = 0; i < arr1.Length; i++)
        {
            merged[i] = arr1[i];
        }

        for (int i = 0; i < arr2.Length; i++)
        {
            merged[arr1.Length + i] = arr2[i];
        }

        Console.Write("Merged Array: ");
        for (int i = 0; i < merged.Length; i++)
        {
            Console.Write(merged[i] + " ");
        }
    }
}
                
OUTPUT

Merged Array: 1 3 5 2 4 6
                    
CODE

using System;

class RemoveDuplicates
{
    static void Main()
    {
        int[] arr = { 1, 2, 2, 3, 4, 4, 5 };
        int n = arr.Length;
        int[] temp = new int[n];
        int j = 0;

        for (int i = 0; i < n - 1; i++)
        {
            if (arr[i] != arr[i + 1])
            {
                temp[j++] = arr[i];
            }
        }
        temp[j++] = arr[n - 1];

        Console.Write("After removing duplicates: ");
        for (int i = 0; i < j; i++)
        {
            Console.Write(temp[i] + " ");
        }
    }
}
                
OUTPUT

After removing duplicates: 1 2 3 4 5
                    
CODE

using System;

class SecondLargest
{
    static void Main()
    {
        int[] arr = { 12, 35, 1, 10, 34, 1 };
        int first = int.MinValue;
        int second = int.MinValue;

        for (int i = 0; i < arr.Length; i++)
        {
            if (arr[i] > first)
            {
                second = first;
                first = arr[i];
            }
            else if (arr[i] > second && arr[i] != first)
            {
                second = arr[i];
            }
        }

        Console.WriteLine("Second Largest Element: " + second);
    }
}
                
OUTPUT

Second Largest Element: 34
                    
CODE

using System;

class JaggedArray
{
    static void Main()
    {
        int[][] jagged = new int[3][];
        jagged[0] = new int[] { 80, 90 };
        jagged[1] = new int[] { 70, 60, 85 };
        jagged[2] = new int[] { 50, 55, 60, 65 };

        for (int i = 0; i < jagged.Length; i++)
        {
            int sum = 0;
            for (int j = 0; j < jagged[i].Length; j++)
            {
                sum += jagged[i][j];
            }
            double avg = (double)sum / jagged[i].Length;
            Console.WriteLine("Average for Student " + (i + 1) + ": " + avg);
        }
    }
}
                
OUTPUT

Average for Student 1: 85
Average for Student 2: 71.6666666666667
Average for Student 3: 57.5
                    
CODE

using System;

class BubbleSort
{
    static void Main()
    {
        int[] arr = { 64, 34, 25, 12, 22, 11, 90 };
        int n = arr.Length;

        for (int i = 0; i < n - 1; i++)
        {
            for (int j = 0; j < n - i - 1; j++)
            {
                if (arr[j] > arr[j + 1])
                {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }

        Console.Write("Sorted Array: ");
        for (int i = 0; i < n; i++)
        {
            Console.Write(arr[i] + " ");
        }
    }
}
                
OUTPUT

Sorted Array: 11 12 22 25 34 64 90
                    
CODE

using System;

class SelectionSort
{
    static void Main()
    {
        int[] arr = { 64, 25, 12, 22, 11 };
        int n = arr.Length;

        for (int i = 0; i < n - 1; i++)
        {
            int min_idx = i;
            for (int j = i + 1; j < n; j++)
            {
                if (arr[j] < arr[min_idx])
                {
                    min_idx = j;
                }
            }

            int temp = arr[min_idx];
            arr[min_idx] = arr[i];
            arr[i] = temp;
        }

        Console.Write("Sorted Array: ");
        for (int i = 0; i < n; i++)
        {
            Console.Write(arr[i] + " ");
        }
    }
}
                
OUTPUT

Sorted Array: 11 12 22 25 64

                    
CODE

using System;

class ConditionalMax
{
    static void Main()
    {
        Console.Write("Enter first number: ");
        int a = Convert.ToInt32(Console.ReadLine());

        Console.Write("Enter second number: ");
        int b = Convert.ToInt32(Console.ReadLine());

        int max = (a > b) ? a : b;

        Console.WriteLine("Maximum number is: " + max);
    }
}

                
OUTPUT

Enter first number: 10
Enter second number: 20
Maximum number is: 20

                    
CODE

using System;

class NestedSwitch
{
    static void Main()
    {
        Console.WriteLine("1. File");
        Console.WriteLine("2. Edit");
        Console.Write("Enter choice: ");
        int mainChoice = Convert.ToInt32(Console.ReadLine());

        switch (mainChoice)
        {
            case 1:
                Console.WriteLine("1. New");
                Console.WriteLine("2. Open");
                Console.Write("Enter File choice: ");
                int fileChoice = Convert.ToInt32(Console.ReadLine());
                switch (fileChoice)
                {
                    case 1: Console.WriteLine("New File Created"); break;
                    case 2: Console.WriteLine("File Opened"); break;
                    default: Console.WriteLine("Invalid File Option"); break;
                }
                break;
            case 2:
                Console.WriteLine("1. Cut");
                Console.WriteLine("2. Copy");
                Console.Write("Enter Edit choice: ");
                int editChoice = Convert.ToInt32(Console.ReadLine());
                switch (editChoice)
                {
                    case 1: Console.WriteLine("Cut Performed"); break;
                    case 2: Console.WriteLine("Copy Performed"); break;
                    default: Console.WriteLine("Invalid Edit Option"); break;
                }
                break;
            default:
                Console.WriteLine("Invalid Main Option");
                break;
        }
    }
}
                
OUTPUT

1. File
2. Edit
Enter choice: 1
1. New
2. Open
Enter File choice: 2
File Opened
                    
CODE

using System;

class SimpleCalculator
{
    static void Main()
    {
        while (true)
        {
            Console.Write("Enter first number: ");
            double num1 = Convert.ToDouble(Console.ReadLine());

            Console.Write("Enter operator (+, -, *, /) or 'x' to exit: ");
            char op = Convert.ToChar(Console.ReadLine());
            
            if (op == 'x') break;

            Console.Write("Enter second number: ");
            double num2 = Convert.ToDouble(Console.ReadLine());

            switch (op)
            {
                case '+': Console.WriteLine("Result: " + (num1 + num2)); break;
                case '-': Console.WriteLine("Result: " + (num1 - num2)); break;
                case '*': Console.WriteLine("Result: " + (num1 * num2)); break;
                case '/': Console.WriteLine("Result: " + (num1 / num2)); break;
                default: Console.WriteLine("Invalid Operator"); break;
            }
            Console.WriteLine();
        }
    }
}
                
OUTPUT

Enter first number: 10
Enter operator (+, -, *, /) or 'x' to exit: *
Enter second number: 5
Result: 50

Enter first number: 20
Enter operator (+, -, *, /) or 'x' to exit: x

                    
CODE

using System;

class LeapYear
{
    static void Main()
    {
        Console.Write("Enter Year: ");
        int year = Convert.ToInt32(Console.ReadLine());

        if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
        {
            Console.WriteLine(year + " is a Leap Year");
        }
        else
        {
            Console.WriteLine(year + " is not a Leap Year");
        }
    }
}
                
OUTPUT

Enter Year: 2024
2024 is a Leap Year
                    
GOHEL MANTHAN - January 30, 2026
‹
›
Home

Creating innovative solutions for a connected world.

Email On

manthangohel04@gmail.com

This website was designed , developed and maintenance by GOHEL MANTHAN © 2026