Equidistant Characters from Start & End ID:5400

Equidistant Characters from Start & End
ID:5400

Given a string value S1 the program must print only the characters which are present in the same position from the start of S1 as well as the end of S1 in the order of their occurrence.

Boundary Condition(s):
1 <= Length of S1 <= 1000

Input Format:
The first line contains S1.

Output Format:
The first line contains the string value containing the characters which are present in the same position from the start of S1 as well as the end of S1.

Example Input/Output 1:
Input:
engine

Output:
en

Example Input/Output 2:
Input:
malayalam

Output:
malay


PROGRAM IN C:

#include<stdio.h>

#include<stdlib.h>


int main()

{

char s[1000],s1[1000];

scanf("%s",s);

for(int i=0;i<strlen(s);i++)

s1[i]=s[i];

for(int i=0,j=strlen(s1)-1;i<strlen(s)&&j>=0;i++,j--)

{

    if(s[i]!=s1[j])

    break;

    printf("%c",s[i]);

}

}

Comments

Popular Posts