View Code of Problem 49

#include<stdio.h>
#define N 10
int main()
{
    int a[N], n;
	int maxi, mini;
	while(scanf("%d", &n) != EOF)
	{
        for(int i = 0; i < n; i++)
	    	scanf("%d", &a[i]);
	    int max = a[0];
    	int min = a[0];
    	for(i = 0; i < n; i++)
		{
	    	if(max < a[i])
			{
		    	max = a[i];
	     		maxi = i;
			}
		    if(min > a[i])
			{
		    	min = a[i];
	    		mini = i;
			}
		}
	    int temp = a[0];
     	a[0] = min;
    	a[mini] = temp;
    	temp = a[n - 1];
    	a[n - 1] = max;
    	a[maxi] = temp;
    	for(i = 0; i < n; i++)
		{
	    	if(!i)
	     	    printf("%d", a[i]);
		    else
		     	printf(" %d", a[i]);
		}
	    printf("\n");
	}
    return 0;
}
/*
Main.c: In function 'main':
Main.c:13:10: error: 'i' undeclared (first use in this function)
      for(i = 0; i < n; i++)
          ^
Main.c:13:10: note: each undeclared identifier is reported only once for each function it appears in
*/

Double click to view unformatted code.


Back to problem 49