51. C Program To find the Second Smallest Number among the given numbers.
How does this program work?
- This code helps to find Second Smallest number from the given numbers using C-Language.
Here is the code
#include <stdio.h>
int main(void)
{
//To find Second smallest number in Array
int a[50];
int n,i,small,new;
printf(" Enter number of elements: \n");
scanf("%d",&n);
printf("Enter %d elements: \n",n);
for(i=0;i < n;i++)
{
scanf("%d",&a[i]);
}
small=new=a[0];
for(i=1;i < n;i++)
{
if(small>a[i])
{
new=small;
small=a[i];
}
else if(new>a[i] && a[i]!=small)
{
new=a[i];
}
}
printf(" The Second Smallest Element in the given Array: %d\n", new);
return 0;
}