Computer Science, asked by veerankikarthikeya, 9 months ago

write a program to copy and print the words which have atleast a pair is consecutive letters in a sentence strings​

Answers

Answered by hmj48845
3

Explanation:

Answer:

The idea is to traverse string from left to right. For every traversed character, print it in a line if it is consecutive to previous one, else print a new line character.

// C++ program to print consecutive characters

// together in a line.

#include <iostream>

using namespace std;

void print(string str)

{

cout << str[0];

for (int i=1; str[i]!='\0'; i++)

{

if ((str[i] == str[i-1]+1) ||

(str[i] == str[i-1]-1))

cout << str[i];

else

cout << "\n" << str[i];;

}

}

// Driver code

int main()

{

string str = "ABCXYZACCD";

print(str);

return 0;

}

Explanation:

THIS IS YOUR ANSWER

THANKS AND MARK AS BRAINLIST

5.0

Read more on Brainly.in - https://brainly.in/question/17239199#readmore

Similar questions