How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / asif
#include <stdio.h>
#include <string.h>
void reverse(char *str)
{
if (*str == '\0')
return;
reverse(str+1);
printf("%c", *str);
}
int main()
{
char str[50];
char *ptr;
printf("Enter the string: ");
//scanf("%s", str);
fgets(str,50,stdin);
ptr = strchr(str,'\n');
*ptr = '\0';
printf("Reversed string: ");
reverse(str);
printf("\n");
return 1;
}
| Is This Answer Correct ? | 2 Yes | 3 No |
Post New Answer View All Answers
What is clrscr ()?
What is else if ladder?
Simplify the program segment if X = B then C ← true else C ← false
Write a program in c to replace any vowel in a string with z?
What are the advantages and disadvantages of c language?
What is signed and unsigned?
illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question
What is meant by errors and debugging?
C language questions for civil engineering
What is static function in c?
Which is better malloc or calloc?
application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above
Is there any demerits of using pointer?
‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.
program to convert a integer to string in c language'