Saturday, August 18, 2018

ADDING TWO DISTANCES


  • Problem Description

    1. Create a Structure called "Distance" 

    2. Create two data members of "Distance Structure" feet(int), inch(float) 

    3. Create three structure variables as d1, d2 and sumOfDistances 4. Get two distances and add the feet and inches.

    Mandatory:

    To add the distance using the structure variables as follows

    1. sumOfDistances.feet=d1.feet+d2.feet

    2 sumOfDistances.inch=d1.inch+d2.inch

    Note: The structure variables, data members and structure name are CASE Sensitive.

    Follow the same case mentioned in the mandatory
  • CODING ARENA
  • #include <stdio.h>
    struct Distance
    {
      int feet;
      float inch;
    }d1,d2,sumOfDistances;
    int main()
    {
      scanf("%d %f\n",&d1.feet,&d1.inch);
      scanf("%d %f\n",&d2.feet,&d2.inch);
      {
        sumOfDistances.feet=d1.feet+d2.feet;
        sumOfDistances.inch=d1.inch+d2.inch;
        printf("Sum of distances=%d feet and %.2f inches",sumOfDistances.feet,sumOfDistances.inch);
      }
      return 0;
    }

        
      
      



  • Test Case 1

    Input (stdin)
    23 8.6
    
    34 2.4
    
    
    Expected Output
    Sum of distances=57 feet and 11.00 inches
  • Test Case 2

    Input (stdin)
    25 11.9
    
    34 2.5
    
    
    Expected Output
    Sum of distances=59 feet and 14.40 inches

1 comment: