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
SSSSS [86.1K]
3 years ago
8

Write a method called consecutive that accepts three integers as parameters and returns true if they are three consecutive numbe

rs—that is, if the numbers can be arranged into an order such that, assuming some integer k, the parameters’ values are k, k 1, and k 2. Your method should return false if the integers are not consecutive. Note that order is not significant; your method should return the same result for the same three integers passed in any order. For example, the calls consecutive(1, 2, 3), consecutive(3, 2, 4), and consecutive(–10, –8, –9) would return true. The calls consecutive(3, 5, 7), consecutive(1, 2, 2), and consecutive(7, 7, 9) would return false.
Computers and Technology
1 answer:
Andre45 [30]3 years ago
7 0

Answer:

#include <iostream>

using namespace std;

void swap(int *a,int *b)

{

   int temp;

   temp=*a;

   *a=*b;

   *b=temp;

}

bool consecutive(int k1,int k2,int k3)

{

   int arr[]={k1,k2,k3};  //storing these variables into an array

   int i,j;

   for(i=0;i<3;i++)

   {

       for(j=i;j<3;j++)

       {

           if(arr[i]>arr[j])

           {

               swap(arr[i],arr[j]);  //swapping to sort these numbers

           }

       }

   }

   if((arr[1]==arr[0]+1)&&(arr[2]==arr[0]+2))  //checks if consecutive

       return true;

   else

       return false;

}

int main()

{

   int result=consecutive(6,4,5);   //storing in a result variable

   if(result==0)

       cout<<"false";

   else

       cout<<"true";

   return 0;

}

OUTPUT :

true

Explanation:

In the above code, it stores three elements into an array and then sorts the array in which it calls a method swap() which is also defined and interchanges values of 2 variables. Then after sorting these numbers in ascending order , it checks if numbers are consecutive or not, if it is true, it returns true otherwise it return false.

You might be interested in
You have a chart that shows 100 data points and you've circled the highest value. Which of the following are you using?
allsm [11]
Option D, The Rudolph Rule is the correct answer.
7 0
3 years ago
Complete the given C program (prob1.cpp) to read an array of integers, print the array, and find the 2nd largest element in the
labwork [276]

Answer:

#include <stdio.h>

int getElement(int arr[], int size) {

   

   int largest2, largest = 0;

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

   {

       if(arr[i] > arr[largest])

       {

           largest = i;

       }

   }

   if(largest != 0)

       largest2 = 0;

   else

       largest2 = size - 1;

   for(int i=0; i<size && i != largest ;i++)

   {

       if(arr[i] > arr[largest2])

           largest2 = i;

   }

   

   return arr[largest2];

}

printArray(int arr[], int size) {

   

   printf("The array is: ");

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

   {

       printf("%d ", arr[i]);

   }

   printf("\n");

}

int main()

{

 

   int arr[5] = {30, 20, 5, 10, 24};

   printArray(arr, 5);

   printf("Second largest number is: %d", getElement(arr, 5));

   return 0;

}

Explanation:

Since you did not provide any code, I wrote it from the scratch. I also added the main function for you to check the result.

<em>printArray</em> function basically prints the element of the array

<em>getElement</em> function:

- Declare the two variables to hold the value for largest and second largest

- Inside the first loop, check if there is any number that is greater than largest, if yes, assign it to largest

- Inside the second for loop, check if there is any number that is greater than largest2, if yes, assign it to largest2 (Be aware that the largest we found in the first loop is excluded)

- Return the second largest

* Notice that we were able to apply this solution since the numbers are unique.

5 0
3 years ago
Assume Flash Sort is being used on a array of integers with Amin = 51, Amax = 71, N=10, m=5 Items are classified according to th
Yuliya22 [10]

Answer:

3

Explanation:

= 1 + (int) (4*(63 - 51)/(71-51)))

= 1 + (int) (4*12/20)

= 1 + (int) (48/20)

= 1 + (int)2.4

= 1 + 2

= 3

8 0
3 years ago
"Write a VBA function that changes the cell value of E3. Create a button on sheet 4 to increase the value by 1. Name this button
Olegator [25]

Answer:

Please follow the steps

1) Open excel

2) Go to Developer Tools

3) Click on "Insert" and then under "ActiveX Controls", click on command button on extreme left.

4) Create two buttons and name them "Higher" and "Lower"

5) Double click on the button which you have named "Higher".

6) A new window will be opened where you have to put the code "Range("E3").Value = Range("E3").Value + 1".

7) Minimize the window and turn off the "Design View"

8) Put any value in E3 to verify the working and click the button named "Higher".

9) Perform the same steps for the button which you have  named "Lower" and put the code "Range("E3").Value = Range("E3").Value - 1".

N.B: If you don't see the developer tools on the top. Click on the File menu and then select Options from the drop down menu. Excel Options window will appear.click on the Customize Ribbon option which you will see on the left. Click on the Developer checkbox under the list of Main Tabs on the right. Then click on the OK button.

Explanation:

Download xlsx
7 0
3 years ago
After conducting interviews with several bad candidates, Althea, a manager at Langrover Inc. interviewed a candidate who was bet
nikdorinn [45]

Answer:

d. The contrast error

Explanation:

<u>Correct option is:</u>

d. The contrast error

  • <em>Contrast Error is a concept during a performance appraisal of a candidate where his/her valuation is impacted by the fact that the previous candidates were relatively good or bad. </em>

8 0
3 years ago
Other questions:
  • What term refers to a piece of software that interfaces with the hardware on your computer?
    10·2 answers
  • You want to verify that the Webpages you create are compliant with an accessibility standard supported by a particular governmen
    15·1 answer
  • What are the two main functions of user accounts in Active Directory? (Choose all that apply.) Allow users to access resources m
    7·2 answers
  • What is another word for controls​
    13·1 answer
  • What does "scanf(\"%d\" mean?
    13·2 answers
  • Marco had a database that showed the first, second, and third favorite ice cream flavors for each person in his school. He used
    11·2 answers
  • Given the message size of 16Kb, packet size of 2Kb, speed of 4Kbps over 3 links, how much time, will it take the message to trav
    6·1 answer
  • I need help with this question!
    11·1 answer
  • 5. Played electronically by manipulating images on a television screen produced by a
    15·1 answer
  • What is a major advantage of medical simulators?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!