Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <unistd.h>
- using namespace std;
- void swap_(int & a, int & b) {
- int c = a;
- a = b;
- b = c;
- }
- int main (){
- int arr[5];
- arr[0]=9; arr[1]=7; arr[4]=7;arr[3]=8; arr[2]=2;
- int j;
- j=arr[0];
- for(int i = 0; i < 5; i++) {
- cout << arr[i] << " ";
- }
- cout << endl;
- for(int i = 0; i < 5; i++) {
- if (arr[i] > j) {
- j = arr[i];
- }
- }
- cout << j << endl;
- for(int j = 0; j < 5; j++) {
- for(int i = 0; i < 4; i++) {
- if (arr[i] > arr[i+1]) {
- swap_(arr[i], arr[i+1]);
- }
- }
- }
- for(int i = 0; i < 5; i++) {
- cout << arr[i] << " ";
- }
- cout << endl;
- /*
- for (int t=0;t<5;t++){
- if(t < arr[t]){
- j=arr[t];
- }
- }
- cout << j <<endl;
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement