Thursday, September 20, 2012

program to add the total time(limit n,using structure)

 program to add the total time(limit n,using structure)
#include<stdio.h>
#include<conio.h>

 struct time
 {
 int h,m,z;
 };
  void main()
  {
  int i,p,q,n,j;
  struct time s[10];
  clrscr();
  printf("Enter the limit\n");
  scanf("%d",&n);
 for(i=0;i<n;i++)
 {printf("Enter the %d time in hh/mm/ss form\n",(i+1));
 scanf("%d%d%d",&s[i].h, &s[i].m ,&s[i].z);
 }
  s[n].h=0;
  s[n].m=0;
  s[n].z=0;
  printf("Time in hh/mm/ss form\n");
 for(i=0;i<n;i++)
 {
 s[n].h=s[n].h+s[i].h;
 s[n].m=s[n].m+s[i].m;
 s[n].z=s[n].z+s[i].z;
 }
  p=s[n].z/60;
  s[n].z=s[n].z%60;
  q= (s[n].m+p)/60;
  s[n].m=(s[n].m+p)%60;
  s[n].h=s[n].h+q;

 printf("%d : %d : %d",s[n].h,s[n].m ,s[n].z);

 getch();
 }

No comments:

Post a Comment