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 :

    1. Input the string
    2. Loop through the entire string to find the numbers.
    3. After finding the number, repeat the previous character the same number of times.
    4. Repeat steps 2 and 3 for the entire string.
    5. 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

Popular posts from this blog

INVERTED PYRAMID STAR PATTERN

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

C PROGRAM TO PRINT THE REMAINING DAYS AND COMPLETED DAYS FROM A GIVEN DATE