C Program to reverse a String

In this post, we will learn how to reverse a string in C language.

For example - If the string is "hello" then, the output is "olleh".


void main()
    int i, j, k;
    char str [100];
    char rev [100];
    printf("Enter a string:\t");
    scanf("%s", str);
    printf("The original string is %s\n", str);
    for(i = 0; str[i] != '\0'; i++);
        k = i-1;
    for(j = 0; j <= i-1; j++)
        rev[j] = str[k];
    printf("The reverse string is %s\n", rev);
Enter a string: ProgrammersDoor
The original string is ProgrammersDoor 
The reverse string is rooDsremmargorP

Happy Coding!

Follow us on Instagram @programmersdoor

Join us on Telegram @programmersdoor

Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem.

Follow Programmers Door for more.

#blog #interview #placement #learn #computer #science

19 views0 comments

Recent Posts

See All

        Contact Us


  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door