I am trying to write a code, which would do this:
Input: Sample
Output: Saammmppppllllleeeeee
This is what I've done so far:
#include <string>
#include <bits/stdc++.h>
#include <cstring>
using namespace std;
int main()
{
string s;
cout << "Input a word: ";
cin >> s;
int n = s.length();
char word[n + 1];
strcpy(word, s.c_str());
for (int i = 0; i < n; i++)
{
if (i > i)
{
int x = i * i;
cout << word[x];
}
}
return 0;
}
This code is supposed to duplicate the next element of the array in this way:
word[0]
is not duplicatedword[1]
is duplicated once (two copies of the element)word[2]
is duplicated three times (three copies of the element) And so on.
How can I do this without using too many void
functions?