ch 9/e3.c
//Function to calculate elapsed time between two time sets

Function to calculate elapsed time between two time sets
Function to calculate elapsed time between two time sets
struct time elapsed_time ( struct time start, struct time end ) 
	{
		struct time elapsed = { 0, 0, 0 } ;
		if ( start.seconds < end.seconds )
			{
				while ( start.seconds < end.seconds )
					{
						elapsed.seconds ++ ;
						start.seconds ++ ;
					}
			}
		else if ( start.seconds >= end.seconds )
			{
				while ( start.seconds < 60 )
					{
						elapsed.seconds ++ ;
						start.seconds ++ ;
					}
				while ( end.seconds > 0 )
					{
						elapsed.seconds ++ ;
						end.seconds -- ;
					}
				elapsed.minutes -- ;
			}
			if ( start.minutes < end.minutes )
			{
				while ( start.minutes < end.minutes )
					{
						elapsed.minutes ++ ;
						start.minutes ++ ;
					}
			}
		else if ( start.minutes >= end.minutes )
			{
				while ( start.minutes < 60 )
					{
						elapsed.minutes ++ ;
						start.minutes ++ ;
					}
				while ( end.minutes > 0 )
					{
						elapsed.minutes ++ ;
						end.minutes -- ;
					}
				elapsed.hours -- ;
			}
			if ( start.hours < end.hours )
			{
				while ( start.hours < end.hours )
					{
						elapsed.hours ++ ;
						start.hours ++ ;
					}
			}
		else if ( start.hours >= end.hours )
			{
				while ( start.hours < 24 )
					{
						elapsed.hours ++ ;
						start.hours ++ ;
					}
				while ( end.hours > 0 )
					{
						elapsed.hours ++ ;
						end.hours -- ;
					}
			}
		if ( elapsed.seconds == 60 )
			{
				elapsed.seconds = 0 ;
				elapsed.minutes += 1 ;
				if ( elapsed.minutes == 60 )
					{
						elapsed.minutes = 0 ;
						elapsed.hours += 1 ;
						if ( elapsed.hours == 24 )
							elapsed.hours = 0 ;
					}
			}
		return elapsed ;	
	}
struct time elapsed_time ( struct time start , struct time end ) { struct time elapsed = { 0 , 0 , 0 } ; if ( start . seconds < end . seconds ) { while ( start . seconds < end . seconds ) { elapsed . seconds ++ ; start . seconds ++ ; } } else if ( start . seconds >= end . seconds ) { while ( start . seconds < 60 ) { elapsed . seconds ++ ; start . seconds ++ ; } while ( end . seconds > 0 ) { elapsed . seconds ++ ; end . seconds -- ; } elapsed . minutes -- ; } if ( start . minutes < end . minutes ) { while ( start . minutes < end . minutes ) { elapsed . minutes ++ ; start . minutes ++ ; } } else if ( start . minutes >= end . minutes ) { while ( start . minutes < 60 ) { elapsed . minutes ++ ; start . minutes ++ ; } while ( end . minutes > 0 ) { elapsed . minutes ++ ; end . minutes -- ; } elapsed . hours -- ; } if ( start . hours < end . hours ) { while ( start . hours < end . hours ) { elapsed . hours ++ ; start . hours ++ ; } } else if ( start . hours >= end . hours ) { while ( start . hours < 24 ) { elapsed . hours ++ ; start . hours ++ ; } while ( end . hours > 0 ) { elapsed . hours ++ ; end . hours -- ; } } if ( elapsed . seconds == 60 ) { elapsed . seconds = 0 ; elapsed . minutes += 1 ; if ( elapsed . minutes == 60 ) { elapsed . minutes = 0 ; elapsed . hours += 1 ; if ( elapsed . hours == 24 ) elapsed . hours = 0 ; } } return elapsed ; }
Function to calculate elapsed time between two time sets
Function to calculate elapsed time between two time sets
//Time structure variable to store elapsed time
 //Calculating elapsed Seconds
 //Adjusting minutes accordingly
 //Calculating elapsed Minutes
 //Adjusting hours
 //Calculating elapsed Hours
 //Adjusting time set into a 24-hour format
