View Code of Problem 49

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

Double click to view unformatted code.


Back to problem 49