BASED ON STRING - Input: a1b2c3 Output: abbccc (ZOHO)
Consider the following I/O samples.
SAMPLE INPUT: i3j2k4
SAMPLE OUTPUT: iiijjkkkk
The algorithm used here is :
- Input the string
- Loop through the entire string to find the numbers.
- After finding the number, repeat the previous character the same number of times.
- Repeat steps 2 and 3 for the entire string.
- Print the output.
C PROGRAM:
#include<stdio.h>
#include<string.h>
int main()
{
char str[100];
int len=0,i,j,n;
printf("Enter the string:");
scanf("%s",&str);
len=strlen(str);
for(i=0;i<len;i++)
{
if(str[i]>'0' && str[i]<'9')
{
n=str[i]-'0';
for(j=0;j<n;j++)
printf("%c",str[i-1]);
}
}
return 0;
}
OUTPUT:
The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.
If you have any feedback about this article and want to improve this, please comment in the comment section.
Comments
Post a Comment