I'm sorry to say this, but...that is pretty much unreadable.
I'm not sure what algorithm you are using, but I doubt if it included quite so many nested if's.
I think the first thing you need to do is look at revising the indentation of that lot, because it is seriously confusing at the moment.
Try starting by changing:
if(reverse==4 && carry==1 && temp==0)
{
s[reverse]=1;
}
else
if(reverse==4 && carry==0 && temp==1)
{
s[reverse]=1;
}
else
if(reverse==4 && carry==0 && temp==0)
To
if(reverse==4 && carry==1 && temp==0)
{
s[reverse]=1;
}
else if(reverse==4 && carry==0 && temp==1)
{
s[reverse]=1;
}
else if(reverse==4 && carry==0 && temp==0)
So that it is clearer without running off the right hand side of the page.
Then look at commenting - I have absolutely no idea why you are doing the tests you are, and without any idea of the algorithm you are trying to implement I can't work it out from that code.
Sorry, but this need to be made readable, and explained a bit better before I can help!