Characters at multiples of X

Example Input/Output 1:
Input:
abcdexyzwqpoolj
5

Output:
eqj

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

#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]);
    }
}
Previous Article

kth largest factor of N - TCS CodeVita

Next Article

Replace Max Digit - Two Integers

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *