Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS1050 - Prelab 4 Spring 2020 Concepts to Practice User-written functions math.h Description For the prelab assignment, you are to write a function called log16()

image text in transcribedimage text in transcribed

CS1050 - Prelab 4 Spring 2020 Concepts to Practice User-written functions math.h Description For the prelab assignment, you are to write a function called log16() to calculate the logarithm base 16 of a number. You may call any function from math.h such as log() or log10() in your implementation of log16(). In your main(), you should loop through powers of 2 starting at 1 (which is 2) up through 4096 and print these numbers along with their log16() - see sample output below. If (like me) you need a refresher on how to convert logarithms, here is some info from Purple Math (https://www.purplemath.com/modules/logrules.htm): In order to evaluate a non-standard-base log, you must use the Change-of-Base formula: Change-of-Base Formula: logo (X) = log2 (6) loga (2) What this rule says, in practical terms, is that you can evaluate a non-standard-base log by converting it to the fraction of the form "(standard-base log of the argument) divided by (same-standard-base log of the non-standard-base)". I keep this straight by looking at the position of things. In the original log, the argument is "above" the base (since the base is subscripted), so I leave things that way when I split them up: log, (x) logat) * log(0) Functions You Must Write You may write any functions you wish to implement this program, in addition to the following functions. However, you must implement the following functions: double log16(double x) - This function returns the log base 16 of x. int main(void) - Of course, you need to write a main(). Hints You should print double numbers with %lf as the formatter. Sample Output jimr@JimRHadesCanyon :/CS1050/SP2020/labs/lab4$ compile prelab4.c jimr@JimRHadesCanyon :-/CS1050/SP2020/labs/1ab4$ ./a.out Log base 16 of 1 = 0.000000 Log base 16 of 2 = 0.250000 Log base 16 of 4 = 0.500000 Log base 16 of 8 = 0.750000 Log base 16 of 16 = 1.000000 Log base 16 of 32 = 1.250000 Log base 16 of 64 = 1.500000 Log base 16 of 128 = 1.750000 Log base 16 of 256 = 2.000000 Log base 16 of 512 = 2.250000 Log base 16 of 1024 = 2.500000 Log base 16 of 2048 = 2.750000 Log base 16 of 4096 = 3.000000 CS1050 - Prelab 4 Spring 2020 Concepts to Practice User-written functions math.h Description For the prelab assignment, you are to write a function called log16() to calculate the logarithm base 16 of a number. You may call any function from math.h such as log() or log10() in your implementation of log16(). In your main(), you should loop through powers of 2 starting at 1 (which is 2) up through 4096 and print these numbers along with their log16() - see sample output below. If (like me) you need a refresher on how to convert logarithms, here is some info from Purple Math (https://www.purplemath.com/modules/logrules.htm): In order to evaluate a non-standard-base log, you must use the Change-of-Base formula: Change-of-Base Formula: logo (X) = log2 (6) loga (2) What this rule says, in practical terms, is that you can evaluate a non-standard-base log by converting it to the fraction of the form "(standard-base log of the argument) divided by (same-standard-base log of the non-standard-base)". I keep this straight by looking at the position of things. In the original log, the argument is "above" the base (since the base is subscripted), so I leave things that way when I split them up: log, (x) logat) * log(0) Functions You Must Write You may write any functions you wish to implement this program, in addition to the following functions. However, you must implement the following functions: double log16(double x) - This function returns the log base 16 of x. int main(void) - Of course, you need to write a main(). Hints You should print double numbers with %lf as the formatter. Sample Output jimr@JimRHadesCanyon :/CS1050/SP2020/labs/lab4$ compile prelab4.c jimr@JimRHadesCanyon :-/CS1050/SP2020/labs/1ab4$ ./a.out Log base 16 of 1 = 0.000000 Log base 16 of 2 = 0.250000 Log base 16 of 4 = 0.500000 Log base 16 of 8 = 0.750000 Log base 16 of 16 = 1.000000 Log base 16 of 32 = 1.250000 Log base 16 of 64 = 1.500000 Log base 16 of 128 = 1.750000 Log base 16 of 256 = 2.000000 Log base 16 of 512 = 2.250000 Log base 16 of 1024 = 2.500000 Log base 16 of 2048 = 2.750000 Log base 16 of 4096 = 3.000000

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

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions