C# Program to Find Smallest Number Taken From User

Here is the code to find the smallest no. in a c sharp program when the numbers are taken from the user. Program has been done using array in visual basic 2008.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication23
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, smallest;
            int[] array = new int[5];
            for (i = 0; i < 5; i++)
            {
                Console.WriteLine(“Enter elements:{0}”, i+1);
                array[i] = Convert.ToInt32(Console.ReadLine());
            }
            smallest = array[0];
            for (i = 0; i <5; i++)
            {
                if (array[i] < smallest)
                {
                    smallest = array[i];
                }
            }
            Console.WriteLine(“The smallest number is :{0}”, smallest);
            Console.ReadLine();
        }
        
    }
        }
    

Add Comment