C Online Compiler
Example: Reverse a String in C using For loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Reverse a String in C using For loop #include <stdio.h> #include <string.h> int main() { char x[100], y[100]; int b, e, c = 0; // b - To store the begin // e - To store the end // c - To store the count printf ("Enter a string to make reverse::\n"); scanf ("%s", &x); // calculation of the string length while (x[c] != '\0') { c++; } e = c - 1; for (b = 0; b < c; b++) { y[b] = x[e]; e--; } y[b] = '\0'; printf("The reverse of the string is : %s\n", y); return 0; }
example
Output
Clear
ADVERTISEMENTS