Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Strings/RemoveOddIndexedCharacters
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;

// Function to remove the odd
// indexed characters from a given string

string removeOddIndexCharacters(string s)
{

// Stores the resultant string
string new_string = "";

for (int i = 0; i < s.length(); i++) {

// If current index is odd
if (i % 2 == 1) {

// Skip the character
continue;
}

// Otherwise, append the
// character
new_string += s[i];
}

// Return the result
return new_string;
}

// Driver Code
int main()
{
string str = "abcdef";

// Function call
cout << removeOddIndexCharacters(str);

return 0;
}