by CodeChum Admin
In order to preserve Spiderman's last words, Mr. Stark wants us to create a program that takes a string and output the string with each proceeding output having one less character until it outputs only one string.
Instructions:
Input
1. String to be processed
Output
Enter·string:·Hello!
Hello!
Hello
Hell
Hel
He
H
#include <iostream>
#include <cstring>
using namespace std;
void preserveString(char str[], int n) {
if (n == 0) {
return;
}
for (int i=0; i<n; i++) {
cout << str[i];
}
cout << endl;
preserveString(str, n-1);
}
int main() {
char str[100];
cout << "Enter string: ";
cin >> str;
preserveString(str, strlen(str));
return 0;
}
Comments
Leave a comment