View Code of Problem 49

#include<stdio.h>
int main()
{
  int a[10],n,i,j,t1,t2;
  int max=0,min=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
   scanf("%d",&a[i]);
   if(a[i]>a[max])
     max=i;
   if(a[i]<a[min])
     min=i;
  }
  t1=a[min];
  a[min]=a[0];
  a[0]=t1;
  t2=a[max];
  a[max]=a[n-1];
  a[n-1]=t2;
  for(j=0;j<n;j++)
  {
    if(j!=n-1)
      printf("%d ",a[j]);
    else
      printf("%d",a[j]);
  }
  return 0;
}

Double click to view unformatted code.


Back to problem 49