C# Program that read array display the smallest integer and sort the array in ascending order by using Array.Sort method.

C# Program that read array display the smallest integer and sorts the array in ascending order by using Array.Sort method.

C# Program that read array display the smallest integer and sort the array in ascending order by using Array.Sort method.

Object:

Write a program in C# to read a one-dimensional integer array from the user, display the smallest integer in the array, and sort the array in ascending order by using Array. Sort method.

Code:

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

namespace TEST2

{

    class Program

    {

        static void Main(string[] args)

        {

            int[] s = new int[10];

            Console.WriteLine(“Please Enter 10 Value of Array. \n”);

            //read array value from user

            for (int i = 0; i < 10; i++)

            {

                s[i] = Convert.ToInt32(Console.ReadLine());

            }

            int smallest_element = s[0];

            Console.WriteLine(“\nDescending Order :”);

            foreach (int a in s)

            {

                Console.WriteLine(a);

            }

            //find smallest value

            for (int i = 1; i < 10; i++)

            {

                if (s[i] < smallest_element)

                {

                    smallest_element = s[i];

                }

            }

            Console.WriteLine(“\nSamllest integer in the Array : ” + smallest_element);

            Array.Sort(s);

            Console.WriteLine(“\nAscending Order :”);

            foreach (int a in s)

            {

                Console.WriteLine(a);

            }

            Console.ReadLine();

        }

    }

}

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

namespace TEST2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] s = new int[10];
            Console.WriteLine("Please Enter 10 Value of Array. \n");
            //read array value from user
            for (int i = 0; i < 10; i++)
            {
                s[i] = Convert.ToInt32(Console.ReadLine());
            }
            int smallest_element = s[0];
            Console.WriteLine("\nDescending Order :");
            foreach (int a in s)
            {
                Console.WriteLine(a);
            }

            //find smallest value
            for (int i = 1; i < 10; i++)
            {
                if (s[i] < smallest_element)
                {
                    smallest_element = s[i];
                }
            }
            Console.WriteLine("\nSamllest integer in the Array : " + smallest_element);
            Array.Sort(s);
            Console.WriteLine("\nAscending Order :");
            foreach (int a in s)
            {
                Console.WriteLine(a);
            }
            Console.ReadLine();

        }
    }
}

Output:

C# Program that read array display the smallest integer and sort the array in ascending order by using Array.Sort method.

Another C# Program: C# Program Calculating the Area of a Rectangle

Another C# Program: C# Program that Subtracts two user-defined numbers

Another C# Program: C# Program Create a class student with a data members name and calculate marks and percentage.

Another C# Program: C# program to count vowels in a string

Another Program: Write a C# program to create a static function factorial and calculate factorial of the number.

Another Program: Write a C# program that reads two arrays and checks whether they are equal.

Another Program: Develop a C# app that will determine the gross pay for each of three employees

Program: Write a C# program to demonstrate the multiple inheritances 

 

1 thought on “C# Program that read array display the smallest integer and sort the array in ascending order by using Array.Sort method.”

  1. Pingback: The C Programming Language Structure with C Language data types

Leave a Comment

Your email address will not be published. Required fields are marked *