WAP to reverse the string

Write a program to reverse the string without using string function

#include<stdio.h>
#include<string.h>

int main() {
   char str[100], temp;
   int i, j = 0;

   printf("Enter the string: ");
   gets(str);

   i = 0;
   j = strlen(str) - 1;

   while (i < j) {
      temp = str[i];
      str[i] = str[j];
      str[j] = temp;
      i++;
      j--;
   }

   printf("Reverse string is: %s", str);
   return (0);
}

Output

Enter the string: nawaraj
Reverse string is: jarawan

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments