Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // laba3_zad2-1
- //
- // Created by Мария Лукашова on 12/11/18.
- // Copyright © 2018 Мария Лукашова. All rights reserved.
- //
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- int compare(const void* a, const void* b) {
- return *(int*) b - *(int*) a;
- }
- int main() {
- const int n = 10;
- int m[n];
- srand(time(NULL));
- for(int i = 0; i < n; i++)
- {
- int numb = rand()%100;
- int znak = rand()%2 + 1;
- if (znak>1){numb*=-1;}
- m[i]=numb;
- cout<<m[i]<<" ";
- }
- cout <<endl;
- qsort(m, n, sizeof(int), compare);
- for (int i = 0; i < n; i++)
- {
- cout << m[i] << " " ;
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement