C program to reverse a string enter by user


Introduction

C program to reverse a string enter by user. I have used Code:: Blocks compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <string.h>

#define MAX_SIZE 100 //Maximum size of the string

int main()
{
    int i, j, lenght;
    char string[MAX_SIZE];
    char reverse[MAX_SIZE];

    printf("Enter a string: ");
    gets(string);

    lenght = strlen(string);
    j = 0;

    for(i=lenght-1; i>=0; i--)
    {
        reverse[j] = string[i];
        j++;
    }
    reverse[j] = '\0';

    printf("Reverse string : %s", reverse);

    return 0;
}

Result

C language

     





Related Topics





Popular Posts