First X Characters for N times

The program must accept a string value S and two integers X and N as the input. The program must print the first X characters of S for N times as the output.
Boundary Condition(s):
1 <= Length of S <= 100
1 <= X <= Length of S
1 <= N <= 100
Input Format:
The first line contains the string S.
The second line contains two integers X and N separated by a space.
Output Format:
The first line contains the first X characters of S for N times.
Example Input/Output 1:
Input:
Rectangle
3 4
Output:
RecRecRecRec
Explanation:
The word formed by the first 3 characters of Rectangle is Rec.
Then Rec is repeated for 4 times as RecRecRecRec.
Hence the output is RecRecRecRec
Example Input/Output 2:
Input:
january
7 2
Output:
januaryjanuary


solution:-

#include<stdio.h>
#include <stdlib.h>

int main()
{
    char s[101];
    int a,b;
    
    scanf("%s\n%d %d",s,&a,&b);
    char arr[a+1];
    
    for(int i=0;i<a;i++)
    {
        arr[i]=s[i];
        
    }
    
    for(int i=0;i<b;i++)
    {
        for(int j=0;j<a;j++)
        {
            printf("%c",arr[j]);
        }
    }
    

}

Comments

Popular posts from this blog

Two Matrix Spiral Print

Alphabets Positions Reversed

Odd Factors - (Error Identification) skillrack program id - 7306