Hi,
How to use a loop function to reverse a counter string?
Thanks,
Printable View
Hi,
How to use a loop function to reverse a counter string?
Thanks,
Using a for Loop to Reverse a String
Try this example:
Code:<HTML>
<BODY>
<H1>
<SCRIPT>
var newString = "";
var theString = "This is a test";
var counter = theString.length;
for (counter ;counter > 0 ;counter -- ) {
newString += theString.substring(counter-1, counter);
}
document.write(theString + " reversed is " + newString + "!");
</SCRIPT>
</H1>
</BODY>
</HTML>
Using a Do/While Loop to Reverse a Text String
Try this example
Code:<HTML>
<BODY>
<H1>
<SCRIPT>
var newString = "";
var theString = "string";
var counter = theString.length;
do
{
newString += theString.substring(counter-1, counter);
counter--;
}
while (counter > 0 );
document.write(theString + " reversed is " + newString + "!");
</SCRIPT>
</H1>
</BODY>
</HTML>
Try this:
I hope this helps you.Code:#include
#include
#include
void main()
{
char str[10],temp;
int i,len;
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i
{
temp=str[i];
str[i]=str[len];
str[len--]=temp;
}
printf("%s",str);
getch();