C Program & Algorithm to find the second biggest element in an array (use user defined function).


#include<stdio.h>
#include<conio.h>
int array[20];
void sort(int x)
{
   int temp,i,j;
   for(i=0;i<x;i++)
   for(j=0;j<x-(i+1);j++)
   {
if(array[j]>array[j+1])
{
   temp=array[j];
   array[j]=array[j+1];
   array[j+1]=temp;
}
   }

}
void main()
{
   int limit,i;
   clrscr();
   printf("\nEnter the limit of array\t: ");
   scanf("%d",&limit);
   printf("\nEnter the array elements\t: ");
   for(i=0;i<limit;i++)
   {
scanf("%d",&array[i]);
   }
   sort(limit);
   printf("\nThe second biggest element is\t: %d",array[limit-2]);
   getch();
}

Algorithm

sort(x)
step1:start
step2:intilize i<-0 p="">step3:check whether i else go to step14
step4:intilize j<-0 p="">step5:check whether j
else go to step12
step6:if array[j]>array[j+1], then go to step7
else go to step10
step7:temp=array[j]
step8:array[j]=array[j+1]
step9:array[j+1]=temp
step10:j=j+1
step11:go to step5
step12:i=i+1
step13:go to step3
step14:stop
main()
step1:start
step2:read limit
step3:intilize i<-0 p="">step4:check whether i
else go to step8
step5:read arrar[i]
step6:i=i+1
step7:go to step 4
step8:call sort (limit)
step9:print array[limit-2]
step10:stop