Saturday, August 18, 2018

POINTERS 48

  • Problem Description

    Write a program to reverse a string using pointer

    Input and Output Format:

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output.
  • CODING ARENA
  • #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("%s",revStr);
      return 0;
    }

      
  • Test Case 1

    Input (stdin)
    SRM university
    
    
    Expected Output
    ytisrevinu MRS
  • Test Case 2

    Input (stdin)
    asdfghjk
    
    
    Expected Output
    kjhgfdsa

No comments:

Post a Comment