I tried your code and it prints 0 as the first number - http://ideone.com/ur9p4N
thanx fr correcting me…hw shud i modify it…plz suggest…
You need to see that we like to help newbies here, but, if we do all the work for you and debug your code for you, you won’t learn much…
From the title of your question you say you can’t find the reason for WA, but, did you even tested your code locally?
Because, as @betlista pointed out, you are printing a 0 at the beginning of the output, which would clearly be something you could have noticed if you had tested your code locally even with trivial examples… Please always expose your questions clearly and concisely so we can help you in the best possible manner, as people may get demotivated to help you if they see you are just here for the AC status and not because you are really struggling…
With this said… you can use scanf("%s",str); to read a string from stdin and you don’t need dynamic strings here…