Characters at multiples of X - Spicy Coders

Recent

Monday, November 13, 2017

Characters at multiples of X

A string S is passed as the input. A positive integer X is also passed as the input. The program must print the characters at positions which are multiples of X. 

Input Format: The first line contains S. The second line contains X. 

Output Format: The first line contains the characters at positions which are multiples of X. 

Boundary Conditions: Length of S will be from 3 to 100. 

Example Input/Output 1: 
Input: 
abcdexyzwqpoolj 

Output: 
eqj 

Explanation: The multiples of 5 are like 5, 10, 15,... So the characters in these positions are e,q,j

Source Code:

#include<stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
    char str[100];
    int x,i;
    fgets(str,100,stdin);
    scanf("%d",&x);
    for(i=1;i<=strlen(str);i++)
    {
       if(i%x==0)
        printf("%c",str[i-1]);
    }

}

2 comments:

  1. Floating point exception (core dumped)...but custom case is working

    ReplyDelete