Computer Science, asked by veerankikarthikeya, 11 months ago

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

Answers

Answered by ItzDazzingBoy
10

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

Answered by monisushmakavila
1

Answer:

mark me has brainliest

Attachments:
Similar questions