Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // laba3_zad2-1
  4. //
  5. // Created by Мария Лукашова on 12/11/18.
  6. // Copyright © 2018 Мария Лукашова. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <stdlib.h>
  11. using namespace std;
  12. int compare(const void* a, const void* b) {
  13.  
  14. return *(int*) b - *(int*) a;
  15. }
  16.  
  17. int main() {
  18. const int n = 10;
  19. int m[n];
  20. srand(time(NULL));
  21. for(int i = 0; i < n; i++)
  22. {
  23.  
  24. int numb = rand()%100;
  25. int znak = rand()%2 + 1;
  26. if (znak>1){numb*=-1;}
  27. m[i]=numb;
  28.  
  29. cout<<m[i]<<" ";
  30. }
  31. cout <<endl;
  32. qsort(m, n, sizeof(int), compare);
  33. for (int i = 0; i < n; i++)
  34. {
  35. cout << m[i] << " " ;
  36. }
  37. cout << endl;
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement