1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include<stdio.h>
#define MINUTE 60
#define HOUR ( MINUTE * 60 )
#define DAY ( HOUR * 24 )
void formatSeconds( int *,int *,int *,int * );
void addS( int,int * );
int main()
{
int seconds = 0,minutes = 0,hours = 0,days = 0,ssAdded = 0;
printf( "Total Seconds: " );
scanf_s( "%d",&seconds );
getchar();
formatSeconds( &seconds,&minutes,&hours,&days );
printf( "Formatted: %d day",days );
addS( days,&ssAdded );
printf( ", %d hour",hours );
addS( hours,&ssAdded );
printf( ", %d minute",minutes );
addS( minutes,&ssAdded );
printf( ", %d second",seconds );
addS( seconds,&ssAdded );
printf( " (%d s's added)",ssAdded );
getchar();
return 0;
}
void formatSeconds( int *seconds,int *minutes,int *hours,int *days )
{
*days = *seconds / DAY;
*seconds = *seconds % DAY;
*hours = *seconds / HOUR;
*seconds = *seconds % HOUR;
*minutes = *seconds / MINUTE;
*seconds = *seconds % MINUTE;
}
void addS( int a,int *ssAdded )
{
if( a != 1 )
{
printf( "s" );
++*ssAdded;
}
}
|