[SOLVED] Input: a2b3c4 and Output: aabbbcccc

Issue

The code I’ve written is not producing any output. It just takes the string as an input:

#include<stdio.h>
#include<conio.h>
#include<string.h>

int main() {
    char str[100];
    int i,size,s,pos;
    scanf("%s", &str);
    size=strlen(str);
    for(i=0;i<size;i++) {
        if((str[i]>=65 && str[i]<=90) || (str[i]>=97 && str[i]<=122)) {
            i++;
        } else {
            if(str[i]>='0' && str[i]<='9') {
                for(s=0;s<str[i];s++) {
                    printf("%s", str[i-1]);
                }
            }
            i++;
        }
    }
}

Solution

#include<stdio.h>
#include<string.h>
int main()
{
char str[100];
int i=0,s;
scanf("%s",str);
while(str[i]!='\0')
{ 
    if(str[i]>='a' && str[i]<='z') 
    {
        i++;            
    }
    else if(str[i]>='A' && str[i]<='Z')
    { 
        i++; 
    }

    else if(str[i]>='0' && str[i]<='9')
        {

            for(s=0;s<str[i]-'0';s++)
            {
            printf("%c", str[i-1]);
            }
            i++;

        }

}

}

Answered By – Umang Jain

Answer Checked By – Pedro (BugsFixing Volunteer)

Leave a Reply

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