0% found this document useful (0 votes)
24 views2 pages

Reverse String

Uploaded by

kulkarniamey546
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Reverse String

Uploaded by

kulkarniamey546
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>

#include <string.h>

void reverseString(char str[], int start, int end) {

if (start < end) {

// Swap characters at start and end indices

char temp = str[start];

str[start] = str[end];

str[end] = temp;

// Recursive call with updated indices

reverseString(str, start + 1, end - 1);

int main() {

char inputString[100];

// Input from the user

printf("Enter a string: ");

fgets(inputString, sizeof(inputString), stdin);

// Remove newline character from input

inputString[strcspn(inputString, "\n")] = '\0';

// Calculate the length of the string

int length = strlen(inputString);

// Reverse the string using the recursive function

reverseString(inputString, 0, length - 1);


// Display the reversed string

printf("Reversed string: %s\n", inputString);

return 0;

You might also like