Thursday, 14 January 2016

Solution of URI 1984 :: The Pronalância Puzzle


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
#include <string.h>
int main()
{
    char num[25], temp;
    scanf("%s", num);
    int lnth = strlen(num);
    int i, j;
    for(i=0, j=lnth-1; i < lnth/2; i++, j--)
    {
        temp = num[i];
        num[i]=num[j];
        num[j]=temp;
    }
    printf("%s\n", num);
    return 0;
}

5 comments:

  1. #include
    #include
    int main()
    {
    char num[25];
    scanf("%s", num);
    printf("%s\n", strrev(num));
    return 0;
    }


    Is my answer right? And why?

    ReplyDelete
    Replies
    1. Your Solution is Correct.
      But you will get Compilation Error on URI.
      Because, strrev() function doesn't work on URI.

      Delete
  2. Oh, I was confused. Thanks for your comment.

    ReplyDelete
  3. Assalamu alaikum

    i < lnth/2 why u use this? i cant understand

    ReplyDelete

Note: only a member of this blog may post a comment.