Friday, August 17, 2018

REVERSE STRING-WITHOUT LIBRARY

  • Problem Description

    Write a C program to find reverse of a string without library function.
  • #include <stdio.h>
    #include <string.h>
    int main()
    {
      char str[100],revStr[100];
      int i,j;
      scanf("%[^\n]s",str);
      j=0;
      for(i=(strlen(str)-1); i>=0; i--)
        revStr[j++]=str[i];
      revStr[j]='\0';
      printf("\n%s",str);
      printf("\n%s",revStr);
      return 0;
    }
        
  • Test Case 1

    Input (stdin)
    SRMUniversity
    
    
    Expected Output
    SRMUniversity
    
    ytisrevinUMRS
  • Test Case 2

    Input (stdin)
    ULCSRM
    
    
    Expected Output
    ULCSRM
    
    MRSCLU

No comments:

Post a Comment