Write a function reverse which takes a strings as a parameter and prints it out in reverse.

Example:

reverse (hello) prints out (olleh)

Questions by yong ha

Showing Answers 1 - 12 of 12 Answers

Try this

Code
  1. void reverse (int idx, char *str ) {

  2.      if (--idx < 0 ) {

  3.           return ;

  4.      } else {

  5.           putchar ( *(str + idx) ) ;

  6.           reverse (idx, str) ;

  7.      }

  8. }

  Was this answer useful?  Yes

ankur

  • Jun 7th, 2012
 

Code
  1. #include<stdio.h>

  2. #include<string.h>

  3. void main()

  4. {

  5. int a,i;

  6. char b[100];

  7. char s[100]="in this world let there be a name and fame to those who can";

  8. a=strlen(s);

  9. for(i=0;i<=s;i++)

  10. {

  11. b[i]=s[a-i];

  12. }

  13. printf("%s",b);

  14. }

  Was this answer useful?  Yes

mahamad

  • Jun 14th, 2012
 

Code
  1. #include<stdio.h>

  2. #include<conio.h>

  3. #include<string.h>

  4. main()

  5. {

  6. char s[100];

  7. int i;

  8. printf("Enter ANy String:=>");

  9. scanf("%s",&s);

  10. printf("-----------Reverse String is---------------

  11. ");

  12. for(i=strlen(s);i>=1;i--)

  13. {

  14.       printf("%c",s[i]);

  15. }

  16. getch();

  17. return 0;

  18. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions