Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Array_interchange large and smallest number

```
// AHF C PROGRAM SOLVING

//solving here 2_D   ARRAY 	programming problem

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

int main()
{
int n,i,large=-9999,small=9999,large_pos,small_pos,temp,arr;

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

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

//checking large number
if(arr[i]>large)
{
large=arr[i];
large_pos=i;
}

//checking small number
if(arr[i] < small)
{
small=arr[i];
small_pos=i;
}
}

//printing optional output
pf("\nThe largest number of the array= %d",large);
pf("\nThe position of the largest number= %d",large_pos);
pf("\nThe smallest number of the array= %d",small);
pf("\nThe position of the smallest number= %d",small_pos);

//interchanging large and small number
temp=arr[large_pos];
arr[large_pos]=arr[small_pos];
arr[small_pos]=temp;

//printing final output after interchange
pf("\nThe new array is:");
for(i=0;i < n;i++)
pf("\t %d",arr[i]);

return 0;
}

```
OUTPUT: