bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

commit 389707b4fd2a205dee5abd484815bd06ed6d6270
parent cf5ff5f67efa088e9fa7f206cb371275ad8a1601
Author: Amit Dutta <amitdutta4255@gmail.com>
Date:   Mon, 30 Mar 2026 18:32:28 +0530

Add recursive string reversal program in C

Implemented a C program that reverses a string using recursion.
Diffstat:
ASemester_1/practice-c/pc015.c | 43+++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+), 0 deletions(-)

diff --git a/Semester_1/practice-c/pc015.c b/Semester_1/practice-c/pc015.c @@ -0,0 +1,43 @@ +/* + * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 30 Mar 2026 + * Repo: https://github.com/notamitgamer/bsc + * License: MIT + */ + +/* Write a C program to reverse a string using a recursive function. */ + +#include<stdio.h> +#include<stdlib.h> +#include<string.h> + +void reverseString(char [], char *, char *); + +int main() { + char string[101], *p, *start, *end; + printf("Enter the string (Max: 100 char): "); + if(fgets(string, sizeof(string), stdin) == NULL) { + printf("\nError reading input."); + exit(1); + } + p = strchr(string, '\n'); + if(p) *p = '\0'; + printf("Before Reverse: %s", string); + start = string; + end = string + strlen(string) - 1; + reverseString(string, start, end); + printf("\nAfter reverse: %s", string); + return 0; +} + +void reverseString(char str[], char *start, char *end) { + if(start >= end) { + return; + } + char temp; + temp = *start; + *start = *end; + *end = temp; + start++; + end--; + reverseString(str, start, end); +}
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror