Expexceted output and output are same but is showing wrong

, ,

#include <stdio.h>

int main(void) {
// your code goes here
int t,a,b,i,e;
char c[100000000];
scanf("%d",&t);
while(t–)
{
scanf("%d%d",&a,&b);
scanf("%s",&c);
if(c[0]==‘0’)
{
c[0]=‘1’;
b–;
}
for(i=a+1;i<=a+b;i++)
{
c[i]=‘0’;
}
for(i=0;i<=a+b;i++)
{
printf("%c",c[i]);
}
if(t>0)
printf("\n");
}
return 0;
}

Can you provide a questions link so that I can help!

You are printing empty spaces. You didn’t see it but the judge read them as characters so thats why you got wrong answer. Your logic is perfectly alright. The reason for printing empty spaces was that you got the indexing wrong. Indexing starts from 0 and goes upto a-1 for a string of size a, so remove the equals sign from <=a+b and make a+1 to a, inside the for loop conditions and for loop initialization respectively.

Good doubt though! Took me a few minutes to figure it out.

1 Like

I got it know and the code is know correct thanks for helping me out.