Saturday, August 18, 2018

STRUCTURE 40

  • Problem Description

    Write a program to read display add and subtract two distances . DIstance must be defined using kms and metres using typedef and function by passing entire structure

    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

    Mandatory

    You have to use structure concept.
  • CODING ARENA
  • #include <stdio.h>
    typedef struct g
    {
    float a,b,c,d,h,j,t,l;
    }ad;

    int main()
      ad g; 
     scanf("%f\t%f\n%f\t%f",&g.a,&g.b,&g.c,&g.d);
    if(g.a>=g.b && g.c>=g.d)
      {
      g.h=g.a+g.b;
      g.j=g.c+g.d;
      g.t=g.a-g.b;
      g.l=g.c-g.d;
      printf("%.f ft %.f inch",g.j,g.h);
      printf("\n%.f ft %.f inch",g.l,g.t);
      }
     else if(g.a>=g.b && g.c<=g.d)
        {
        g.h=g.a+g.b;
        g.j=g.d+g.c;
        g.t=g.a-g.b;
        g.l=g.d-g.c;
        printf("%.f ft %.f inch",g.j,g.h);
        printf("\n%.f ft %.f inch",g.l,g.t);
        }
      else if(g.a<=g.b && g.c>=g.d)
        {
        g.h=g.a+g.b;
        g.j=g.c+g.d;
        g.t=g.b-g.a;
        g.l=g.c-g.d;
        printf("%.f ft %.f inch",g.h,g.j);
        printf("\n%.f ft %.f inch",g.t,g.l);
        }
      else
        {
        g.h=g.a+g.b;
        g.j=g.c+g.d;
        g.t=g.b-g.a;
        g.l=g.d-g.c;
        printf("%.f ft %.f inch",g.j,g.h);
        printf("\n%.f ft %.f inch",g.l,g.t);
        }
    return 0;
    }
  • Test Case 1

    Input (stdin)
    23 33
    
    33 33
    
    
    Expected Output
    56 ft 66 inch
    
    10 ft 0 inch
  • Test Case 2

    Input (stdin)
    33 333
    
    12 33
    
    
    Expected Output
    45 ft 366 inch
    
    21 ft 300 inch

No comments:

Post a Comment