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
Disadvatage of using a computer when you don't have knowledge about it​
shtirl [24]

If you mean you have no knowledge of the subject you're supposed to be researching, than that's the disadvantage, because you will have many,many different pages for what the search engines can relate what you're searching on to what it hints will help.

Disadvantages of using a computer when you don't know how to use a computer.

You don't know how to use a computer.

7 0
4 years ago
The goal of the ____ memory allocation algorithm is to find the smallest memory block into which a job will fit.
Pani-rosa [81]
The goal of the BEST-FIT memory allocation algorithm is to find the smallest memory block into which a job will fit.
5 0
2 years ago
Read 2 more answers
Image
Eduardwww [97]

Answer:

B. x = 90

Explanation:

  • 180 = 135 + y
  • y = 45
  • 45 + 45 = 90
5 0
3 years ago
Read 2 more answers
According to the rules of economics, all resources arein their supply. The wants and needs of people are. The more scarce a reso
pshichka [43]

To make choices/decisions.

The principle of scarcity forces people to make choices or decisions about how to allocate resources efficiently. These choices are made to satisfy basic needs and as much additional wants as possible. This principle of Scarcity in economics further states that, limited goods and services are available to meet unlimited wants. Even resources considered plenty and free in monetary, somehow, are scarce in some sense. It is in the capacity of an individual to buy some or all commodities as per the available resources with that individual.

6 0
4 years ago
Read 2 more answers
Which behavior demonstrates initiative?
Marysya12 [62]
Introducing yourself to a new coworker and offering to answer their questions.
6 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following is a Microsoft solution that runs on a Microsoft Terminal Services server but appears, to end users, as i
    10·1 answer
  • Megara would like to create a web page using web design software, but she does not have any money to spend. What would you sugge
    15·1 answer
  • Now, Kim wants to add the technical terms she typically misspells to the PowerPoint built-in list. Which option should she use t
    15·2 answers
  • When would you use a template when working with word 2013?
    15·1 answer
  • 2. Name the three building blocks of design that pertain to form.
    7·1 answer
  • Florida law requires every child blank years of age or younger use a crash tested federally be approved child restraint device
    5·2 answers
  • Hello<br> mini crewmate :) ඞ
    12·2 answers
  • The process of converting an input file (stream of characters) into an understandable format is called syntax analysis.
    7·1 answer
  • Explain how you would set up a Demilitarized Zone on. You have 25 workstations and a server on your site. Explain what additiona
    5·1 answer
  • Imagine an everyday scenario in which you are using the internet: downloading a file, uploading a photo, checking your email, et
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!