Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program needs to be in C Part I You can find out how many seconds have elapsed since Jan 1, 1970 using the time() function.

Program needs to be in C

Part I

You can find out how many seconds have elapsed since Jan 1, 1970 using the time() function.

#include

now = time(NULL); // now is more than a billion seconds (which data type should you use?)

Write a program that estimates how many years, months, weeks, days, and hours have gone by since Jan 1 1970 by calculations with the number of seconds that have passed.

The number of months must be less than 12, i.e., take out how many years have gone by first, then how many months are left, then weeks, etc.

Assume that all years have 365 days, and all months have 30.42 days.

Dont use a calculator, or any web site that reports the number of seconds in a month, etc. your C program can calculate anything that you need. Notice that this is an assignment on using arithmetic in C.

Hints. How many seconds are in a minute? hour? A day? A week? A month? A year?

Part II

Ask the user to enter a number between 1 and 20. If they enter a number outside of that range, print an error message, and call the function:

exit(-1); // stop the program immediately with an error code of -1.

Use a switch statement to output the corresponding Roman numeral for the number that they entered. Note that you dont have to do any calculations for this, just a big switch with 20 cases, and a default case for numbers out of range.

Part III

You can generate a random number in C using the following code:

int myRandomNumber;

srand(time(NULL)); // seed the random number generator

myRandomNumber = rand(); // each time you call this function there will be a different random number.

Generate a random number, and output it. Use if statements to determine if the number is odd or even, and output a message to that effect. Similarly, output if the number is divisible by 3, and if it is divisible by 10. Use the % operator to achieve this.

Run the program, and print the results several times using different numbers to be sure that its working.

Hint: In C you can not declare variables after you write executable code. For example if you call the srand function, and then declare some more variables after that call, the program will not compile. The compiler messages are not very helpful. Put all the variable declarations at the top of the function.

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

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions