Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help me with the following C programming questions below ! sample Code : #define _CRT_SECURE_NO_WARNINGS #include #include int main() { int hour, minute,

Can you help me with the following C programming questions below !

sample Code :

#define _CRT_SECURE_NO_WARNINGS

#include #include

int main() { int hour, minute, second, hour1, minute1, second1, secondSum, minuteSum, hourSum, finaleHour, finaleMinute, finaleSecond, finaleDays; char msg[20] = "", result[10] = ""; printf("Enter an initial 24-hour time as hours minutes and seconds (0 to stop): "); scanf("%d %d %d", &hour, &minute, &second); printf("Enter the time to add as hours minutes and seconds: "); scanf("%d %d %d", &hour1, &minute1, &second1); secondSum = second + second1; minuteSum = minute + minute1; hourSum = hour + hour1; minuteSum = minuteSum + secondSum / 60; hourSum = hourSum + minuteSum / 60; finaleDays = hourSum / 24; finaleSecond = secondSum % 60; finaleMinute = minuteSum % 60; finaleHour = hourSum % 24;

if (finaleDays == 1) strncat(msg, "tomorrow", 10); else if (finaleDays > 1) { sprintf(result, "%d", finaleDays); strncat(msg, "in ", 4); strncat(msg, result, 4); strncat(msg, " days", 5);

}

if (finaleSecond < 10) { if (finaleMinute < 10) if (finaleHour < 10) printf("Total is 0%d:0%d:0%d %s", finaleHour, finaleMinute, finaleSecond, msg); else printf("Total is %d:0%d:0%d %s", finaleHour, finaleMinute, finaleSecond, msg); else if (finaleHour < 10) printf("Total is 0%d:%d:0%d %s", finaleHour, finaleMinute, finaleSecond, msg); else printf("Total is %d:%d:0%d %s", finaleHour, finaleMinute, finaleSecond, msg); } else { if (finaleMinute < 10) if (finaleHour < 10) printf("Total is 0%d:0%d:%d %s", finaleHour, finaleMinute, finaleSecond, msg); else printf("Total is %d:0%d:%d %s", finaleHour, finaleMinute, finaleSecond, msg); else if (finaleHour < 10) printf("Total is 0%d:%d:%d %s", finaleHour, finaleMinute, finaleSecond, msg); else printf("Total is %d:%d:%d %s", finaleHour, finaleMinute, finaleSecond, msg); }

return 0; }

Execution and Output Example

Enter an initial 24-hour time as hours minutes and seconds: 7 30 50

Enter the time to add as hours minutes and seconds: 1 29 50

Total is 9:00:40 AM

Enter an initial 24-hour time as hours minutes and seconds 7 30 0

Enter the time to add as hours minutes and seconds: 5 0 0

Total is 12:30:00 PM

Enter an initial 24-hour time as hours minutes and seconds: 7 30 0

Enter the time to add as hours minutes and seconds: 25 30 0

Total is 9:00:00 AM tomorrow

Enter an initial 24-hour time as hours minutes and seconds 7 30 0

Enter the time to add as hours minutes and seconds: 49 30 0

Total is 9:00:00 AM in 2 days

Questions:

1. Explain how modulus is used in your calculations. Describe one other technique for performing the calculations and compare it to the use of modulus. Does modulus simplify the calculations?

2. Adding times is similar to adding two 3 digit numbers. You add them digit by digit and, when the sum exceeds 9, you do a carry. Explain how adding number is similar to adding times and where the two techniques differ and why.

3. Assume that, instead of adding hours, minutes and seconds, you need to add years, months and days. What new problems would you encounter solving this problem that you did not have to worry about in the addition of times? Describe how you would solve these problems.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions