Program to reverse a String - Coding is Funny

Program to reverse a String

Program to reverse a String

Below is a program to reverse a string in C language.
#include<stdio.h>
#include<conio.h>
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];
        k--;
    }
    printf("The reverse string is %s\n", rev);
    getch();
}

OUTPUT:

Enter a string: studytonight The original string is studytonight The reverse string is thginotyduts

  • Share: