1. Write a program that converts time in minutes to time in hours and minutes. Use #define or const to create a symbolic constant for 60. Use a while loop to allow the user to enter values repeatedly and terminate the loop if a value for the time of 0 or less is entered.
#include <stdio.h>
int main(void) {
const int minperhour = 60;
int minutes, hours, mins;
printf("Enter the number of minutes to convert: ");
scanf("%d", &minutes);
while (minutes > 0) {
hours = minutes / minperhour;
mins = minutes % minperhour;
printf("%d minutes = %d hours, %d minutes\n", minutes, hours, mins);
printf("Enter next minutes value (0 to quit): ");
scanf("%d", &minutes);
}
printf("Bye\n");
return 0;
}
3. Write a program that asks the user to enter the number of days and then converts that value to weeks and days. For example, it would convert 18 days to 2 weeks, 4 days. Display results in the following format:
18 days are 2 weeks, 4 days.
Use a while loop to allow the user to repeatedly enter day values; terminate the loop when the user enters a nonpositive value, such as 0 or -20.
#include <stdio.h>
int main(void) {
const int daysperweek = 7;
int days, weeks, day_rem;
printf("Enter the number of days: ");
scanf("%d", &days);
while (days > 0) {
weeks = days / daysperweek;
day_rem = days % daysperweek;
printf("%d days are %d weeks and %d days.\n", days, weeks, day_rem);
printf("Enter the number of days (0 or less to end): ");
scanf("%d", &days);
}
printf("Done!\n");
return 0;
}
5. Write a program that requests a type double number and prints the value of the number cubed. Use a function of your own design to cube the value and print it. The main() program should pass the entered value to this function.
#include <stdio.h>
void showCube(double x);
int main(void) {
double val;
printf("Enter a floating-point value: ");
scanf("%lf", &val);
showCube(val);
return 0;
}
void showCube(double x) {
printf("The cube of %e is %e.\n", x, x * x * x);
}