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
How to delete audio from powerpoint​
Marta_Voda [28]

Answer:

To delete an audio clip, select the audio icon on the slide and press Delete.

Hope it helps!!!!

4 0
3 years ago
What substance was the first photograph made from?
dybincka [34]

Answer:

bitumen

Explanation:

5 0
4 years ago
Which statement regarding hard drives is incorrect?
Veseljchak [2.6K]

Answer: I think the answer is

c. solid state drives are less expensive than magnetic hard drives

Explanation:

4 0
3 years ago
Read 2 more answers
In a(n) __________ situation, a wireless device is configured to appear to be a legitimate access point, enabling the operator t
Basile [38]

Answer:

A) Malicious Association,

Hope this helps.

Explanation:

7 0
3 years ago
How many bits are necessary for a binary representation (unsigned) of
Musya8 [376]
A. 5
b. as an unsigned int: 9. Normally a year is 365.25 days which would require 32-bits for an IEEE float.
c. 25
3 0
4 years ago
Other questions:
  • WILL GIVE BRANLYIST
    6·1 answer
  • Who played a leading role in perfecting movable type for printing?
    15·1 answer
  • Although you can use a dialog box to indent paragraphs, word provides a quicker way through the ____.
    7·1 answer
  • It will gain you more knowledge, intensify your soft skills, strong work ethics and grow your network. What is it?​
    12·2 answers
  • If you want to learn more about a command, point to its button and wait for the ____ to appear.
    13·1 answer
  • An inventory clerk, using a computer terminal, views the following on screen: part number, part description, quantity on hand, q
    8·1 answer
  • Write a program to randomly fill an array of float of 10 elements (use the rand() function and make sure to use #include ) in ma
    11·1 answer
  • Consider the following code segment.
    5·1 answer
  • Which subscription service complements App-ID by enabling you to configure the next-generation firewall to identify and control
    6·1 answer
  • a functional policy declares an organization's management direction for security in such specific functional areas as email, rem
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!