Home Basic Loop Array string Function Pointer Contact STUDY

# AHF    C    PROGRAM    SOLVING

### Array_print second largest and smallest number with position separately

```
// AHF C PROGRAM SOLVING

//solving here 2_D   ARRAY 	programming problem

#include<stdio.h>
#include<math.h>
#define pf printf

int main()
{
int i,n,arr,max=-9999,small=9999,pos1,pos2;

int second_max=-10000,second_small=10000,pos3,pos4;

pf("Enter the number of element in the array: ");
scanf("%d",&n);

pf("\nEnter the array element: ");
for(i=0;i < n;i++)
scanf("%d",&arr[i]);    //taking array element

//finding maximum number and its position
for(i=0;i < n;i++)
{
if(arr[i]>max)
{
max=arr[i];
pos1=i;
}
}

//finding second maximum number and its position
for(i=0;i < n;i++)
{
if(arr[i]!=max)
{
if(arr[i]>second_max)
{
second_max=arr[i];
pos3=i;
}
}
}

//finding minimum number and its position
for(i=0;i < n;i++)
{
if(arr[i] < small)
{
small=arr[i];
pos2=i;
}
}

//finding second minimum number and its position
for(i=0;i < n;i++)
{
if(arr[i]!=small)
{
if(arr[i] < second_small)
{
second_small=arr[i];
pos4=i;
}
}
}

//printing given input
pf("\nThe array you entered:");
for(i=0;i < n;i++)
pf("\t%d",arr[i]);

pf("\nThe maximum number is: %d",max);

pf("\nThe position of the maximum number: %d",pos1);

pf("\nThe small number is: %d",small);

pf("\nThe position of the minimum number: %d",pos2);

pf("\nThe second maximum number is: %d",second_max);

pf("\nThe position of the second maximum number: %d",pos3);

pf("\nThe second small number is: %d",second_small);

pf("\nThe position of the second small number: %d",pos4);

return 0;
}

```
OUTPUT: