# Day 6 Let's Review Hackerrank Solution in C | 30 Days of Code

Write a Program to find the Day 6 Let's Review Hackerrank Solution in C with a logical explanation with output. So in this hackerrank day 6 Let's Review problem, we have to find the even and odd characters of a string. First, we have to print the even space of string characters, then write two spaces and, in the end, print the odd number of characters in a single line. Let's understand and find a hackerrank day 6 solution with an example given below.

Suppose the string is programmingwithbasics after solving this programming challenge. We will get the following output. In the below output, we can see that the pormigihais characters are coming on; even places and rgamnwtbsc are occurring in an odd place, and between them is two spaces. This is logic to solve a Day 6 Hackerrank Solution in C and other programming languages. As we know that this problem belongs to 30 days of code hackerrank challenge.

Given a string, S, of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as two space-separated strings on a single line (see the Sample below for more detail).

Note: 0 is considered to be an even index.

Input Format

The first line contains an integer, T (the number of test cases).
Each line i of the T subsequent lines contain a String, S.

Constraints

1<=T<=10
2<=length of S<=10000

Output Format

For each String Sj (where 0<=j<=T-1), print Sj's even-indexed characters, followed by a space, followed by Sj's odd-indexed characters. Get a Day 6 Let's Review Hackerrank Solution in C programming language.

Sample Input

2
Hacker
Rank

Sample Output

Hce akr
Rn ak

Explanation

Test Case 0: S="Hacker"

S = "H"
S = "a"
S = "c"
S = "k"
S = "e"
S = "r"

The even indices are 0, 2, and 4, and the odd indices are 1, 3, and 5. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S's even indices (Hce), and the second string contains the ordered characters from S's odd indices (akr). Let's check the second test case of Hackerrank Day 6 Solution in C

Test Case 1: S="Rank"

S = "R"
S = "a"
S = "n"
S = "k"

The even indices are 0 and 2, and the odd indices are 1 and 3. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S's even indices (Rn), and the second string contains the ordered characters from S's odd indices (ak).

## Day 6 Let's Review Hackerrank Solution in C

``````#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main()
{
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n; char s;
scanf("%d",&n);

for(int i=0;i<n;i++)
{
scanf("%s",s);
myFunction(s);
}
}

void myFunction(char s[])
{
for(int i=0;i<strlen(s);i++)
{
if (i%2 == 0)
{
printf("%c",s[i]);
}
}

printf(" ");

for(int i=0;i<strlen(s);i++)
{
if (i%2 != 0)
{
printf("%c",s[i]);
}
}

printf("\n");
}``````

### Explanation of Day 6 Let's Review Hackerrank Solution in C

Let's Review Hackerrank Solution in C explanation here. We first divide the string into even and odd numbers as we can see that in the string "Hacker," H is in an even place, and a is in an odd place and so on. So our string is "Hacker" and can be divided by even (H), odd (a), even (c), odd (k), even (e), and odd (r).

Step 1: The first step of Hackerrank Day 6 Solution in C. Run the first loop up to the size of the string and find the even character and print the even place character and print like below.

``````for(int i=0;i<s.size();i++)
{
if(i%2==0)
cout<<s[i];
}``````

after the first loop completes the print space so we can print and separate the second loop. This is the last step of Day 6 Hackerrank Solution in C.

``cout<<" ";``

Step 2: Run the second loop up to the size of the string and find the odd place character and print the odd place character and print like below.

``````for(int i=0;i<s.size();i++)
{
if(i%2!=0)
cout<<s[i];
}``````

At the end print the new line for the next input to the early and next input print in the new line.

``cout<<endl;``

### Similar to 30 Days of Code

Previous Post
Next Post

#### post written by: Ghanendra Yadav

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.