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
Alinara [238K]
4 years ago
7

python Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value i

s considered a CONSECUTIVE DUPLICATE. In this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6. Note that the last 3 is not a consecutive duplicate because it was preceded by a 7. Write some code that uses a loop to read such a sequence of non-negative integers, terminated by a negative number. When the code finishes executing, the number of consecutive duplicates encountered is printed. In this case,3 would be printed. ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input.
Computers and Technology
1 answer:
Vika [28.1K]4 years ago
7 0

int firstNumber,secondNumber = -1, duplicates = 0;

do {

cin >> firstNumber;

if ( secondNumber == -1) {

secondNumber = firstNumber;

}else {

if ( secondNumber == firstNumber )

duplicates++;

else

secondNumber = firstNumber;

}

} while(firstNumber > 0 );

cout << duplicates;

You might be interested in
Write an algorithm for a program which inputs the lengths a, b and c of the three
Dmitriy789 [7]

Hello,

Answer:

<h2>--//Triangles Algorithm</h2>

Declare the variables of the side of each triangle, in this case, a, b, and c, and input them.

If a^2 == b^2 + c^2

           display "This triangle IS right-angled."

Else

          display "This triangle is NOT right-angled

Explanation:

The meaning of the word "algorithm" in this situation would be the coding of the program that you are assigned to create. I'll use Python in this. Display, in this case, will mean "print"

6 0
3 years ago
Read 2 more answers
This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.
Papessa [141]

Answer:

This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.: for - 3.

4 0
4 years ago
Read 2 more answers
Anyone happy about hbo max?
mel-nik [20]

Answer:

I am very happy about it, its very good

8 0
4 years ago
_____ are systems of electronic components that generate, modify, and control sound.
expeople1 [14]
<span>Synthesizers. The term synthesizer is derived from the word synthesis which means to combine various elements to create something new. Instruments such as the trumpet, guitar, drums, etc. are molded and shaped to make a specific sound. With the use of electronic synthesizers sounds can be combined or modified to create a unique, new sound.</span>
4 0
4 years ago
8.11 LAB: Count characters - functions Write a program whose input is a character and a string, and whose output indicates the n
Shkiper50 [21]

Answer:

#include<iostream>

using namespace std;

int CountCharacters(char userChar, const string inputstr){

   int k = 0;

   int iter = 0;

   for (iter = 0; iter < inputstr.size(); iter++){

       if (inputstr[iter] ==  userChar){

           ++k;        }}

   return k;}

int main(){

   string str;

   char userChar[1];

   cout<<"Char: ";    cin>>userChar;

   cin.ignore();

   cout<<"String: ";   getline(cin, str);

   cout<<CountCharacters(userChar[0],str);

   return 0;}

Explanation:

Written in C++:

The function is defined here:

int CountCharacters(char userChar, const string inputstr){

This initializes a count variable k to 0

   int k = 0;

This initializes an iterating variable iter to 0

   int iter = 0;

This iterates through the characters of the string being passed to the function

   for (iter = 0; iter < inputstr.size(); iter++){

This checks for matching characters

       if (inputstr[iter] ==  userChar){

If found,  k is incremented by 1

           ++k;        }}

This returns the total count

   return k;}

The main begins here

int main(){

This declares a string variable

   string str;

This declares a character variable

   char userChar[1];

This gets input for the character variable

   cout<<"Char: ";    cin>>userChar;

This lets the user get another input

   cin.ignore();

This gets input for the string variable

   cout<<"String: ";   getline(cin, str);

This calls the function and return the count of character in the string

   cout<<CountCharacters(userChar[0],str);

6 0
3 years ago
Other questions:
  • Who usually signs a collection letter?
    15·2 answers
  • Who are some of my emails not all deleting on my android i have to use my laptop to see them to delete them?
    12·2 answers
  • A student is helping a friend with a home computer that can no longer access the Internet. Upon investigation, the student disco
    9·1 answer
  • To use a resource from a module, you write the name of the module as a qualifier, using which symbol before the name of the reso
    14·1 answer
  • What is the output <br>this is a computer science question ​
    8·1 answer
  • A technician is configuring a new SOHO multifunction wireless router at a customer’s location to provide network access to sever
    12·1 answer
  • Give your definition of a stored procedure. Based on the Academic Database, identify and describe a scenario where it would be n
    12·1 answer
  • In Full Screen Reading View, which area is reduced?
    14·1 answer
  • What is the purpose of a computer network needs assessment? to evaluate how to move from the current status to the desired goal
    15·1 answer
  • How do we find the time complexity for this algorithm?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!