Saturday, August 18, 2018

IO 15

  • Problem Description

    write a program to swap two numbers using a temporary variable

    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>
    int main()
    {
      int a,b,temp;
      scanf("%d%d",&a,&b);
      printf("Before Swapping");
      printf("\nx=%d",a);
      printf("\ny=%d",b);
      temp=a;
      a=b;
      b=temp;
      printf("\nAfter Swapping");
      printf("\n%d",a);
      printf("\n%d",b);
      

    return 0;
    }
  • Test Case 1

    Input (stdin)
    10
    
    20
    
    
    Expected Output
    Before Swapping
    
    x=10
    
    y=20
    
    After Swapping
    
    20
    
    10
  • Test Case 2

    Input (stdin)
    4
    
    5
    
    
    Expected Output
    Before Swapping
    
    x=4
    
    y=5
    
    After Swapping
    
    5
    
    4

No comments:

Post a Comment