Second smallest number in array by R4R Team

Array:
Array is the collection of different values having same data type.
-We have a integer Array that having all integer values.
-Character array is known as String.

Example-
Array is {3,2,4,1,5}
Second smallest element is 2

program-

#include < stdio.h>
int main()
{
int a[100],n,i,j,t;
printf("Enter number of elements\n");
scanf("%d",&n);
printf("Enter %d number in array\n",n);
//input in array
for(i=0;i< n;i++)
{
scanf("%d",&a[i]);
}
//sort the data
for(i=0;i< n;i++)
{
for(j=i;j< n;j++)
{
if(a[j]< a[i])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
//After sort
printf("Second smallest number is %d",a[1]);
}


output-

Enter number of elements
6
Enter 6 number in array
2 1 5 0 4 3
Second Smallest number is 1




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!