View Code of Problem 49

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

/*
Main.c:3:15: error: expected ';', ',' or ')' before '&' token
 void temp(int &a,int &b)
               ^
Main.c: In function 'main':
Main.c:21:2: warning: implicit declaration of function 'temp' [-Wimplicit-function-declaration]
  temp(a[0],a[min]);
  ^
*/

Double click to view unformatted code.


Back to problem 49