Reverse a String coderinme

Reverse a String coderinme

Reverse a String coderinme
To print the reverse of an entered string, we use the strlen() function and a for loop.
We know String is an array of characters. Arrays have character range between 0 to length-1. Thus we have position of last character in variable ‘j’.Current Values of ‘i’ and ‘j’ are – ‘i’ positioned on first character and ‘j’ positioned on last character. Now we are swapping characters at position ‘i’ and ‘j’. After interchanging characters we are incrementing value of ‘i’ and decrementing value of ‘j’.If i crosses j then process of interchanging character is stopped.
Let’s code this program quickly in C

#include<stdio.h>
#include<string.h>
int main()
{
char a[100];
int i,len;
printf("Enter any String: ");
gets(a);
printf("Your entered string is: %s\n",a);
printf("Your reversed string is: ");
len = strlen(a);
for( i = len ; i >= 0 ; i--)
{
printf("%c",a[i]);
}
printf("\n");
getch();
return 0;
}

For more programs in C, visit our C Coder Archives

Reverse a String coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.