text: Encrypt a string by repeating i | C ++ implementation of the approach ; Function to return the encrypted string ; Number of times the current character will be repeated ; Repeat the current character in the encrypted string ; Driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; string encryptString ( string str , int n ) { int i = 0 , cnt = 0 ; string encryptedStr = " " ; while ( i < n ) { cnt = i + 1 ; while ( cnt -- ) encryptedStr += str [ i ] ; i ++ ; } return encryptedStr ; } int main ( ) { string str = " geeks " ; int n = str . length ( ) ; cout << encryptString ( str , n ) ; return 0 ; }