Saturday, August 18, 2018

STRUCTURE 41


  • Problem Description

    Write a program to read display add and subtract of two time variables defined using hours , minutes and seconds using typdef and passing structure variable as argument in functions.

    Input and Output Format:

    Refer sample input and output for formatting specification
  • CODING ARENA
  • #include <stdio.h>
    struct time
    {
      int hours,minutes,seconds;
    };
    void add(int,int,int,int,int,int);
    int main()
    {
      struct time t1,t2;
      scanf("%d %d %d",&t1.hours,&t1.minutes,&t1.seconds);
      scanf("%d %d %d",&t2.hours,&t2.minutes,&t2.seconds);
      add(t1.hours,t1.minutes,t1.seconds,t2.hours,t2.minutes,t2.seconds);
      return 0;
    }
    void add(int x,int y,int z,int a,int b,int c)
    {
      int h,m,s;
      h=x+a;
      m=y+b;
      s=z+c;
      printf("%d hrs\n",h);
      printf("%d min\n",m);
      printf("%d sec\n",s);
      

    }
  • Test Case 1

    Input (stdin)
    12 12 33
    
    3 1 3
    
    
    Expected Output
    15 hrs
    
    13 min
    
    36 sec
  • Test Case 2

    Input (stdin)
    0 0 1
    
    0 1 1
    
    
    Expected Output
    0 hrs
    
    1 min
    
    2 sec

No comments:

Post a Comment