Thursday, September 13, 2018

REVERSE A STRING


  • Problem Description

    "If an Integer N, write a program to reverse the given number.
    Input

    The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.
    Output

    Display the reverse of the given number N.
    Constraints

    1 <= T<= 1000
    1 <= N <= 100000
    "
  • CODING ARENA
  • #include <stdio.h>
    int main()
    {
      int t;
      scanf("%d",&t);
      while(t--)
      {
        int num;
        scanf("%d",&num);
        int rev=0;
        while(num)
        {
          rev=rev*10+num%10;
          num/=10;
        }
        printf("%d",rev);
        printf("\n");
      }
      return 0;
    }

  • Test Case 1

    Input (stdin)
    3 
    
    12345
    
    31203
    
    2123
    
    
    Expected Output
    54321
    
    30213
    
    3212
  • Test Case 2

    Input (stdin)
    2
    
    78657
    
    100034
    
    
    Expected Output
    75687
    
    430001

No comments:

Post a Comment