View Code of Problem 49

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




return 0;
}

Double click to view unformatted code.


Back to problem 49