Answered Questions

  • Write a C program to reverse the string without using strrev() function?

    Star Read Best Answer

    Editorial / Best Answer

    Rohan  

    • Member Since Nov-2005 | Feb 18th, 2006


    #include <stdio.h>
    #include <conio.h>
    #include <string.h>

    void main()
    {
       char *str;
       int i,len;

      //not using any temp variable and assume we can use only string array and   length

       printf("Enter String : ");
       scanf("%s",str);
       len=strlen(str)-1;
       for(i=0;i<strlen(str)/2;i++)
       {
             str[i]+=str[len];
             str[len]=str[i]-str[len];
             str[i]=str[i]-str[len--];
       }
       printf("Reverse String is : %s",str);
       getch();
    }

    naveen

    • Jun 17th, 2017

    Code
    1. #include<stdio.h>
    2. #include<conio.h>
    3. #include<string.h>
    4.  
    5. void main()
    6. {
    7. char str[10],temp;
    8. int i,len;
    9. printf("enter string: ");
    10. scanf("%s",str);
    11. len=strlen(str)-1;
    12. for(i=0;i<strlen(str)/2;i++)
    13. {
    14. temp=str[i];
    15. str[i]=str[len];
    16. str[len--]=temp;
    17. }
    18. printf("reverse string : %s" ,str);
    19. getch();
    20. }
    21.  

    Gurjyot Singh

    • Dec 5th, 2016

    Here`s the answer

    Code
    1. #include<stdio.h>
    2. #include<conio.h>
    3. #include<string.h>
    4. int main()
    5. {
    6.         char A[20];
    7.         int i;int C=0;
    8.         printf("Enter String :
    9. ");
    10.         gets(A);
    11.         for(i=0;A[i]!=;i++)
    12.         {
    13.                 C++;
    14.         }
    15.         for(A[C]=;C>=0;C--)
    16.         {
    17.                 printf("%c",A[C]);
    18.         }
    19.  
    20.         getch();
    21.         return 0;
    22. }
    23.