Thursday, September 13, 2018

PRINTING PREVIOUS

  • Problem Description

    Latha and Trisha are friends. They love to play with words. Ishu gives them a task to replace each characters in a string with its previous letter. Can you help them to complete this task?
  • CODING ARENA
  • #include <stdio.h>
    #include <string.h>
    int main()
    {
      int a[100],i,l;
      char s1[100];
      scanf("%s",s1);
      l=strlen(s1);
      for(i=0;i<l;i++)
      {
        a[i]=s1[i];
        a[i]=a[i]-1;
        s1[i]=a[i];
      }
      printf("%s",s1);

    return 0;
    }
  • Test Case 1

    Input (stdin)
    bcd
    
    
    Expected Output
    abc
  • Test Case 2

    Input (stdin)
    bqqb
    
    
    Expected Output
    appa

1 comment:

  1. main.c: In function ‘main’:
    main.c:7:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[100]’ [-Wformat=]
    scanf("%s",&s1);
    ^

    ReplyDelete