I am working on a project in a class at school and I am required to convert a unit of minutes (ie 130 Minutes) to Hours and Minutes (ie 2 HOurs and 10 Minutes). If anyone knows a trick to do this please let me know.
I am working on a project in a class at school and I am required to convert a unit of minutes (ie 130 Minutes) to Hours and Minutes (ie 2 HOurs and 10 Minutes). If anyone knows a trick to do this please let me know.
Try the following code:
#include <stdio.h>
#include <stdlib.h>
int numMinutes = 103; /* ie 1 hour 43 minutes */
int main ( void )
{
if ( (numMinutes / 60) == 1 ) /* display 'x' hour... */
printf("%01d hour",numMinutes/60);
else /* display 'x' hours .... */
printf("%01d hours",numMinutes/60);
if ( (numMinutes % 60) == 1) /* display 'x' minute... */
printf(" %01d minute\n",numMinutes%60);
else /* display 'x' minutes....*/
printf(" %01d minutes\n",numMinutes%60);
return 0;
}
#include<stdio.h>
int time = 0; /* Total time in minutes */
int minutes = 0;
int hours = 0;
int main()
{
time = 130; /* Set time to total minutes */
minutes = time % 60; /* Divide by 60 minutes and and take
the ramainder as left over minutes */
/* remove left over minutes from time to get even number and
divide by 60 to get total hours */
hours = (time - minutes) / 60;
printf("Total minutes %d = %d hours and %d minutes\n", time,
hours, minutes);
return(0);
}
Hope that chunk of code helps u with your school work
int min;
int hr;
min=130;
while(min>60)
{
hr++;
min=min-60;
}/***********will loop twice leaving 2 in hr and10 in min*/
good luck.