1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Harlamova29_29 [7]
3 years ago
15

Cerinţa Se dau două numere naturale nenule n și p. Afișați în ordine crescătoare puterile lui n mai mici sau egale cu p. Date de

intrare Programul citește de la tastatură numerele n și p. Date de ieşire Programul afișează pe ecran, în ordine crescătoare, puterile lui n mai mici sau egale cu p, separate prin câte un spațiu. Restricţii şi precizări 2 ≤ n ≤ 10 1 ≤ p < 1.000.000.000
Computers and Technology
1 answer:
rjkz [21]3 years ago
8 0

Given an array of integers (both odd and even), sort them in such a way that the first part of the array contains odd numbers sorted in descending order, rest portion contains even numbers sorted in ascending order.

Explanation:

  • Partition the input array such that all odd elements are moved to left and all even elements on right. This step takes O(n).
  • Once the array is partitioned, sort left and right parts individually. This step takes O(n Log n).

#include <bits/stdc++.h>  

using namespace std;  

void twoWaySort(int arr[], int n)  

{

   int l = 0, r = n - 1;  

   int k = 0;  

   while (l < r) {  

       while (arr[l] % 2 != 0) {  

           l++;  

           k++;  

       }

       while (arr[r] % 2 == 0 && l < r)  

           r--;  

       if (l < r)  

           swap(arr[l], arr[r]);  

   }  

   sort(arr, arr + k, greater<int>());  

   sort(arr + k, arr + n);  

}

int main()  

{  

   int arr[] = { 1, 3, 2, 7, 5, 4 };  

   int n = sizeof(arr) / sizeof(int);  

   twoWaySort(arr, n);  

   for (int i = 0; i < n; i++)  

       cout << arr[i] << " ";  

   return 0;  

}

You might be interested in
Which of the following translates packets so that the node can understand them once they enter through a port?
zubka84 [21]

Answer:

The node translates on its own.

Explanation:

3 0
3 years ago
Read 2 more answers
A paradigm innovation occurs when:
Viktor [21]
B. Because major shifts in thinking can cause change.
4 0
3 years ago
____________________ memory is the ability to add RAM without shutting down the computer or operating system.
Liula [17]

Answer:

Hot-add

Explanation:

The computer system is a electronic device that is used to perform computational task on input data for a pre-dertermined result. The components of the computer is divided into hardware and software components.

The hardware components are the physical parts of the computer system, while the software component are the instructions that runs the system.

The RAM is a physical component that provides memory for running current activities on the monitor screen. When it is removed or faulty, the screen goes blank. To add more RAM memory to the system while the system is on, activate the hot-add memory settings.

4 0
3 years ago
C++ a. Write a program that uses the function isPalindrome given in example 6-6 (Palindrome). Test your program on the followinn
Whitepunk [10]

Answer:

#include <iostream>

#include <array>

using namespace std;

bool isPalindrome(string str)  

{  

int length = str.length();  

for (int i = 0; i < length / 2; i++)  

 if (toupper(str[i]) != toupper(str[length - 1 - i]))

  return false;  

return true;  

}

int main()

{

array<string, 6> tests = { "madam", "abba", "22", "67876", "444244", "trymEuemYRT" };

for (auto test : tests) {

 cout << test << " is " << (isPalindrome(test) ? "" : "NOT ") << "a palindrome.\n";

}

}

Explanation:

The toupper() addition forces characters to uppercase, thereby making the comparison case insensitive.

5 0
3 years ago
What do the points on this website do?
DanielleElmas [232]

Answer:

They allow you to ask more questions and also your rank goes up or down.

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • A drivers touches a cars steering wheel on a hot day which term refers to the way heat is transferredd to the drivers hand
    6·2 answers
  • How did mark watney survive the accident
    9·1 answer
  • Jeanne writes a song, and Raul wants to perform
    6·2 answers
  • Which flooring option is most economical
    11·1 answer
  • What output is generated by this for loop?
    6·1 answer
  • A pedometer treats walking 2,000 steps as walking 1 mile. Write a program whose input is the number of steps, and whose output i
    14·1 answer
  • Write a program in python to make the figure:-
    12·1 answer
  • Which storage is faster than secondary storage​
    14·2 answers
  • Is anybody willing to gift me V bucks? Gamer tag: SpiffyPlop
    13·2 answers
  • In disc brakes, pads are forced against the of a brake disc​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!