Solution- Taking the string from a user and print its all substring on the console as given
Input: "abc"
// C++ program to print permutations
// of a given string with spaces.
#include <cstring>
#include <iostream>
using namespace std;
/* Function recursively prints
the strings having space pattern.
i and j are indices in 'str[]' and
'buff[]' respectively */
void printPatternUtil(const char str[],
char buff[], int i,
int j, int n)
{
if (i == n)
{
buff[j] = '\0';
cout << buff << endl;
return;
}
// Either put the character
buff[j] = str[i];
printPatternUtil(str, buff, i + 1, j + 1, n);
// Or put a space followed by next character
buff[j] = ' ';
buff[j + 1] = str[i];
printPatternUtil(str, buff, i + 1, j + 2, n);
}
// This function creates buf[] to
// store individual output string and uses
// printPatternUtil() to print all permutations.
void printPattern(const char* str)
{
int n = strlen(str);
// Buffer to hold the string
// containing spaces
// 2n - 1 characters and 1 string terminator
char buf[2 * n];
// Copy the first character as
// it is, since it will be always
// at first position
buf[0] = str[0];
printPatternUtil(str, buf, 1, 1, n);
}
// Driver program to test above functions
int main()
{
const char* str = "abc";
printPattern(str);
return 0;
}
Step by stepSolved in 2 steps
- String: abcdefghijklmnopqrstuvwxyzyxwvutsr qponmlkjihgfedcba Make a program that: reads a letter from standard input print the above string up to this letter For example, if the letter was c, the output would be: abcba Must use a function and Pythonarrow_forwardScala Programming: Given string str, write a Scala program to create a new string where "Scala " is added to the front of a given string. If the string already begins with "Scala", return the string unchanged. Otherwise, return the string after adding "Scala ". Test the function for two strings "Scala Programming" and "Programming" inside the main method.arrow_forwardWrite a function that accepts either a pointer to a C-string, or a string object, as its argument. The function should return the character that appears most frequently in the string. Demonstrate the function in a complete program.arrow_forward
- Do in Scala languagearrow_forwardIn C# Given a string, create a function to reverse the case. All lower-cased letters should be upper-cased, and vice versa. Examples ReverseCase("Happy Birthday") -> "hAPPY bIRTHDAY" ReverseCase("MANY THANKS") -> "many thanks" ReverseCase("sPoNtAeEoUs") -> "SpOnTaNeOuS"arrow_forwardA String object in Java is considered to be mutable, i.e., the characters it contains can be changed by its methods. True Falsearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education