View Code of Problem 49

#include<stdio.h>
#include<string.h>
int main(){
	int n,buf[10],max,min,tmp;

	scanf("%d%s",&n,buf);

	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(buf[i]>buf[j]){
				max = i;
				min = j;
			}
		}
	}

	tmp = buf[0];
	buf[0] = buf[min];
	buf[min] = tmp;
	tmp = buf[n-1];
	buf[n-1] = buf[max];
	buf[max] = tmp;

	printf("%s",buf);
  return 0;

}

Double click to view unformatted code.


Back to problem 49