Robert_Manea

Min/Max sortare

Dec 1st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main(){
  6. int n,j,i,v[30],aux=0;
  7.  
  8. printf("introdu n:");
  9. scanf("%d",&n);
  10.  
  11. for(i=0;i<n;i++){
  12. scanf("%d",&v[i]);
  13. }
  14.  
  15. for(i=0;i<n-1;i++){
  16. for(j=i+1;j<n;j++){
  17. if(v[i]>v[j]){
  18. aux=v[i];
  19. v[i]=v[j];
  20. v[j]=aux;
  21. }
  22. }
  23. }
  24.  
  25. printf("Minimul este: %d\n", v[0]);
  26. printf("Maximul este: %d", v[n-1]);
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment