diff --git a/String/Reverse_A_String.c b/String/Reverse_A_String.c new file mode 100644 index 0000000..e4bf987 --- /dev/null +++ b/String/Reverse_A_String.c @@ -0,0 +1,65 @@ +//C Program to reverse a string: +//Problem Statement: Given a string of size N. Reverse the string and display it. + +/* Algorithm- +To reverse a string : +1. Start +2. Declare a user-defined function revstr() +3. Run a for loop using the swapping logic in definition of revstr() +4. Run another for loop for displaying the reversed string +5. Under main() take user input for string. +6. Call revstr() in main() +7. Stop +*/ + +#include //included the standard input/output header file + +//User-Defined Function Body containing logic: +void revstr(char s[]) /*declaring and defining user-defined function, revstr() + which reverses a string by using swapping logic*/ +{ + int a, n; //initializing a counter variable 'a' and another 'n' + int temp = 0; //initializing a temporary variable 'temp' to store the swapped value + for(n=0; s[n] != 0; n++); //a for loop to check if s[] is empty or not + for(a=0; a