Results 1 to 4 of 4

Thread: How to use a loop function to reverse a counter string?

  1. #1
    Join Date
    Aug 2009
    Posts
    12

    How to use a loop function to reverse a counter string?

    Hi,

    How to use a loop function to reverse a counter string?

    Thanks,

  2. #2
    Join Date
    Apr 2008
    Posts
    22

    Re: How to use a loop function to reverse a counter string?

    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>

  3. #3
    Join Date
    May 2008
    Posts
    29

    Re: How to use a loop function to reverse a counter string?

    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>

  4. #4
    Join Date
    Aug 2009
    Posts
    10

    Re: How to use a loop function to reverse a counter string?

    Try this:

    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();
    I hope this helps you.

Similar Threads

  1. How to fix reverse arrow key function on Mac Office 2011
    By BonnieT in forum Windows Software
    Replies: 16
    Last Post: 26-11-2011, 02:42 PM
  2. Replies: 4
    Last Post: 18-04-2010, 05:15 AM
  3. How the reverse() function can be used in C++
    By BossBattle in forum Software Development
    Replies: 5
    Last Post: 20-02-2010, 04:55 PM
  4. program to reverse a string in java.
    By Deepest BLUE in forum Software Development
    Replies: 3
    Last Post: 26-11-2009, 11:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,529,659.46722 seconds with 17 queries