Thursday, September 13, 2018

INCREMENT AND OUTPUT

  • Problem Description

    Get a n value from the user and print 1 to n and again print in reverse as n-1 to 1 as output using increment and decrement operator.
  • CODING ARENA::
  • #include <stdio.h>
    int main()
    {
      int n,i,j;
      scanf("%d",&n);
      for(i=1;i<=n;i++)
        {
        printf ("%d ",i);
      }
      for(j=n-1;j>0;j--)
        printf ("%d ",j);

    return 0;
    }
  • Test Case 1

    Input (stdin)
    15
    
    
    Expected Output
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
  • Test Case 2

    Input (stdin)
    6
    
    
    Expected Output
    1 2 3 4 5 6 5 4 3 2 1

No comments:

Post a Comment