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];
    }
    if(a[i]<a[i-1])
    {
      temp1=a[i-1];
      temp2=a[i];
    }
    i++;
  }
  a[0]=temp2;
  a[n-1]=temp1;
  for(i=0;i<n;i++)
  {
    if(i!=n-1)
    printf("%d ",a[i]);
    else
      printf("%d",a[i]);
  return 0;
}
/*
Main.c: In function 'main':
Main.c:10:5: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int' [-Wformat=]
     scanf("%d",a[i]);
     ^
Main.c:32:1: error: expected declaration or statement at end of input
 }
 ^
*/

Double click to view unformatted code.


Back to problem 49