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
posledela
3 years ago
13

How to get the absolute value in coding begginners?

Computers and Technology
2 answers:
Darina [25.2K]3 years ago
5 0

abs() will give you the absolute value of an integer.

Bezzdna [24]3 years ago
4 0

Answer:

not sure but i took this l;ast year

Explanation:

You might be interested in
You are asked to simulate a binary search algorithm on an array of random values.An array is the list of similar type of element
Alex Ar [27]

Answer:

Explanation:

Problem statement:

to simulate a binary search algorithm on an array of random values.

Binary Search: Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.

Input/output description

Input:

Size of array: 4

Enter array:10  20 30 40

Enter element to be searched:40

The Output will look like this:

Element is present at index 3

Algorithm and Flowchart:

We basically ignore half of the elements just after one comparison.

Compare x with the middle element.

If x matches with middle element, we return the mid index.

Else If x is greater than the mid element, then x can only lie in right half subarray after the mid element. So we recur for right half.

Else (x is smaller) recur for the left half.

The Flowchart can be seen in the first attached image below:

Program listing:

// C++ program to implement recursive Binary Search

#include <bits/stdc++.h>

using namespace std;

// A recursive binary search function. It returns

// location of x in given array arr[l..r] is present,

// otherwise -1

int binarySearch(int arr[], int l, int r, int x)

{

   if (r >= l) {

       int mid = l + (r - l) / 2;

       // If the element is present at the middle

       // itself

       if (arr[mid] == x)

           return mid;

       // If element is smaller than mid, then

       // it can only be present in left subarray

       if (arr[mid] > x)

           return binarySearch(arr, l, mid - 1, x);

       // Else the element can only be present

       // in right subarray

       return binarySearch(arr, mid + 1, r, x);

   }

   // We reach here when element is not

   // present in array

   return -1;

}

int main(void)

{ int n,x;

cout<<"Size of array:\n";

cin >> n;

int arr[n];

cout<<"Enter array:\n";

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

{ cin >> arr[i]; }

cout<<"Enter element to be searched:\n";

cin>>x;

int result = binarySearch(arr, 0, n - 1, x);

   (result == -1) ? cout << "Element is not present in array"

                  : cout << "Element is present at index " << result;

   return 0;

}

The Sample test run of the program can be seen in the second attached image below.

Time(sec) :

0

Memory(MB) :

3.3752604177856

The Output:

Size of array:4

Enter array:10  20 30 40

Enter element to be searched:40

Element is present at index 3

Conclusions:

Time Complexity:

The time complexity of Binary Search can be written as

T(n) = T(n/2) + c  

The above recurrence can be solved either using Recurrence T ree method or Master method. It falls in case II of Master Method and solution of the recurrence is Theta(Logn).

Auxiliary Space: O(1) in case of iterative implementation. In case of recursive implementation, O(Logn) recursion call stack space.

8 0
2 years ago
¿Por qué se considera importante la electricidad en el mundo actual?​
harkovskaia [24]

Es importante porque produce efectos de iluminación, de calor, de mecánica, de química, entre otros, a través del movimiento de los electrones de los átomos.

3 0
2 years ago
When packets are routed on the Internet, the route for a particular packet is not pre-
Ivanshal [37]

Answer:

She notices the website is using a different font and logo, and that the emails are suspiciously worded:

Explanation:

8 0
2 years ago
An interstate route with even numbers travels north/south. True or false?
lisov135 [29]

Answer:

I believe the answer is False

7 0
3 years ago
Read 2 more answers
How you would implement controls to secure guest-to-host interaction between the virtualized operating systems and their hypervi
GarryVolchara [31]

Answer:

Guest to host interaction means that, virtualized operating system is guest and computer system is host. The virtualized operating system is making interaction with computer by using its hardware resources such as storage and CPU, it is also known as host.

<u>Explanation</u>

To make sure the interaction between virtualized operating system and their hyper visors, following steps would be needed.

  1. up to date software and security patches.
  2. Use host based firewalls
  3. Install antivirus
  4. disable unused virtual Hardware
  5. Disable unnecessary file sharing

It is also necessary to monitor the activities between guest and host.

8 0
3 years ago
Other questions:
  • The sun produces energy by the process of nuclear: <br><br> A.fission <br> B.fusion
    7·2 answers
  • Text line breaks and returns are controlled using which tags?
    5·2 answers
  • When 2 or more computers are connected it is called?
    14·1 answer
  • Contemporary operation of networking technology is possible only through the usage of open-use technology and layering approache
    13·1 answer
  • A _____ is a number that summarizes an encrypted information. digital certificate hash function message digest hash algorithm
    8·1 answer
  • True or false, cloud storage does not require internet access?
    9·1 answer
  • I really want to know the best way to deal as much heart as possible plz tell me
    7·2 answers
  • You are interested in buying a laptop computer. Your list of considerations include the computer's speed in processing data, its
    11·1 answer
  • Which of the following describes a recording scout's job in the music industry?
    5·2 answers
  • You can easily merge files even if each file contains a different record layout. Group of answer choices True False
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!