Write a program to give the following output for the given input
Eg 1: Input: a1b10
Output: abbbbbbbbbb
Eg: 2: Input: b3c6d15
Output: bbbccccccddddddddddddddd
The number varies from 1 to 99.
#include<stdio.h>
#include<string.h>
int main()
{
char str[100],temp;
int i,j,x,k;
scanf("%s",str);
for(i=0;i<strlen(str);i=i+2)
{
temp=str[i];
if(str[i+2]>='0' && str[i+2]<='9')
{
x=((str[i+1]-48)*10)+(str[i+2]-48);
for(k=0;k<x;k++)
{
printf("%c",temp);
}
i++;
}
else
{
for(j=0;j<str[i+1]-48;j++)
{
printf("%c",temp);
}
}
}
return 0;
}
Eg 1: Input: a1b10
Output: abbbbbbbbbb
Eg: 2: Input: b3c6d15
Output: bbbccccccddddddddddddddd
The number varies from 1 to 99.
#include<stdio.h>
#include<string.h>
int main()
{
char str[100],temp;
int i,j,x,k;
scanf("%s",str);
for(i=0;i<strlen(str);i=i+2)
{
temp=str[i];
if(str[i+2]>='0' && str[i+2]<='9')
{
x=((str[i+1]-48)*10)+(str[i+2]-48);
for(k=0;k<x;k++)
{
printf("%c",temp);
}
i++;
}
else
{
for(j=0;j<str[i+1]-48;j++)
{
printf("%c",temp);
}
}
}
return 0;
}
No comments:
Post a Comment