Home C Language Basic C Programs Reverse a String in C using for loop

Reverse a String in C using for loop


Write a program in C to print individual characters of string in reverse order.

#include<stdio.h>

#include<string.h>

int main()

{

   char str[100];

   int i;

   printf(“Enter a string:\n”);

   scanf(“%s”,str);

   printf(“Reverse order of given string is:\n”);

   for(i=strlen(str)-1;i>=0;i–)

      printf(“%c”,str[i]);

   printf(“\n”);

   return 0;

}

Output:

Enter a string:

Welcome

Reverse order of given string is:

emocleW