213k views
3 votes
Write a function nexthour that receives one integer argument, which is an hour of the day, and returns the next hour. This assumes a 12-hour clock; so, for example, the next hour

after 12 would be 1. Here are two examples of calling this function:

>> fprintf('The next hour will be %d.\\',nexthour(3))The next hour will be 4.>> fprintf('The next hour will be %d.\\',nexthour(12))The next hour will be 1.

1 Answer

3 votes

Answer:

The function in C is as follows:

int nexthour(int tme){

tme = tme%12 + 1;

return tme;

}

Step-by-step explanation:

This defines the function

int nexthour(int tme){

Ths calculates the next hour using % operator

tme = tme%12 + 1;

This returns the next hour

return tme;

}

User Steffen Langer
by
4.5k points