Write a program to find out second smallest element of an unsorted array



 /*Program to calculate second smallest element using array

Author : Priyanshu , Date: April 21,2021*/


#include<stdio.h>

#include<conio.h>


main()

  {

     int arr[10000],size,i,temp,second;

     clrscr();


     printf("Enter size in between (1 to 10000) : ");

     scanf("%d",&size);



     for(i=0;i<size;++i)

{

   printf("Enter element of array: ");

   scanf("%d",&arr[i]);

}

     temp = arr[0];

     for(i=1;i<size;++i)

{

   if(temp > arr[i] )

      {

second =temp;

temp = arr[i];

      }

   else

      {

if(temp <arr[i] && arr[i] < second)

    {

       second = arr[i];

    }

      }

}

     printf("\nSecond smallest number using array: %d",second);

     getch();

     return(0);

  }

Comments