GeekInterview.com
Series: Subject: Topic:
Question: 33 of 587

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

Example:

reverse (hello) prints out (olleh)
Asked by: yong ha | Member Since Dec-2011 | Asked on: Dec 3rd, 2011

View all questions by yong ha

Showing Answers 1 - 4 of 4 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. }

  
Login to rate this answer.

Code
  1.  
  2. void reverse(char *str)
  3. {
  4.     int i = 0;
  5.     for (i = 0; str[i] !=; i++) {
  6.         printf("%c", str[i]);
  7.         getch();
  8.     }
  9.  

  
Login to rate this answer.
ankur

Answered On : 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. }

  
Login to rate this answer.
mahamad

Answered On : 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. }

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.