Question

For the lab assignment, you are to write a function to calculate the logarithm of a...

For the lab assignment, you are to write a function to calculate the logarithm of a number for an arbitrary base. This function should be named logAny() and it should take parameters of the number whose log you wish to calculate, and the base to be used. 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 logAny(double x, double b) – This function returns the log base b of x. For example, logAny(8,2) should return 3 (because 2 to the 3rd power is 8 and thus 3 is the log base 2 of 8). int main(void) – Of course, you need to write a main().

Code in C

Homework Answers

Answer #1

Code :

I have used inbuilt function in C to calculate log().

This log() function is in math.h header file, so I included that too, in my program.

#include <stdio.h>
#include <math.h> 

//function to calculate logx where base is b
double logAny(double x, double b) 
{
    float p = log(x);
    float q = log(b);
    return p/q;
}


int main()
{
    printf("Enter the number and its base : ");
    float x,b;
    scanf("%f%f", &x,&b);
    float ans = logAny(x,b);
    
    printf("%0.3f", ans);
    return 0;
}

Output :

Try running above code on your own system.

Like, if this helped:)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
**No math library function is allowed in this assignment. You HAVE TO use loop structure to...
**No math library function is allowed in this assignment. You HAVE TO use loop structure to do the calculation** Write a C function named integerPower with the following prototype:   double integerPower(int base, int exponent); This function shall compute and return the value of base exponent The main function shall ask the user to enter the values for the two parameters (based and exponent) and then pass them to the function. The main function shall then display the returned value from...
Your assignment is to write a c++ function that can calculate values for any 5 th...
Your assignment is to write a c++ function that can calculate values for any 5 th order polynomial function. ?(?) = ?0 + ?1? + ?2? 2+?3? 3 + ?4? 5 + ?5? 5 Your function should accept only two parameters, the first parameter should be the value of x at which to calculate y(x). The second parameter should be an array with 6 elements that contain the coefficients a0 to a5. The output of your function should be the...
Write a C++ program which consists of several functions besides the main() function. 1)   The main()...
Write a C++ program which consists of several functions besides the main() function. 1)   The main() function, which shall ask for input from the user (ProcessCommand() does this) to compute the following: SumProductDifference and Power. There should be a well designed user interface. 2)   A void function called SumProductDifference(int, int, int&, int&, int&), that computes the sum, product, and difference of it two input arguments, and passes the sum, product, and difference by-reference. 3)   A value-returning function called Power(int a,...
Write a C/C++ program that performs the tasks described below. If there is just 1 command-line...
Write a C/C++ program that performs the tasks described below. If there is just 1 command-line argument and it is -hw you should simply print hello world and then exit(0). Otherwise, the program should provide a function named mm_alloc. This is the function prototype: void *mm_alloc(int num_bytes_to_allocate) mm_alloc function should obtain space for the user from a block which you obtain via mmap. You should obtain the block on the first invocation and the block size should be some number...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. I had asked this before but the solution I was given did not work. #include #include using namespace std; void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sammy";    reverse(name);    cout << name << endl; //should display...
Write a program that contains a main function and a custom, void function named show_larger that...
Write a program that contains a main function and a custom, void function named show_larger that takes two random integers as parameters. This function should display which integer is larger and by how much. The difference must be expressed as a positive number if the random integers differ. If the random integers are the same, show_larger should handle that, too. See example outputs. In the main function, generate two random integers both in the range from 1 to 5 inclusive,...
Write the functions which are called in the main function given. YOU MAY ASSUME THAT THE...
Write the functions which are called in the main function given. YOU MAY ASSUME THAT THE USER ENTERS A VALID INTEGER. printDouble should accept one value and should print the value of that number times 2. printEndMessage should not accept any values and should print a message indicating that the program has finished. def main(): num1 = int(input("Please enter your number ")) printDouble(num1) printEndMessage() main()
For this lab assignment you will need to write some code and create some graphs. You...
For this lab assignment you will need to write some code and create some graphs. You may use excel to create your graphs, or other language of your choice. Your data needs to demonstrate the experimental running time for Selection Sort (code in book), Merge Sort (code in book), and the Arrays.sort() method. Here is a basic outline of how you need to code this assignment. 1) Create several arrays of size 100, 1000, 10000, 100000, 1000000, … (you need...
For this question you will write two (2) constructors in the implementation file: CylinderType.cpp (Assume that...
For this question you will write two (2) constructors in the implementation file: CylinderType.cpp (Assume that the base class CircleType has a default constructor & assigns 1.0 to its private double radius) part (a) // The first constructor is a default constructor. Please use height as the CylinderType's private member name in the body. // It will create a CylinderType object with a radius of 1.0 and height of 1.0 part (b)    // The second constructor should have two...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class and a Node class (please name your classes exactly ​as I did here). Please follow the below specifications for the two classes. Node.cpp ● This must be a generic class. ● Should contain a generic member variable that holds the nodes value. ● Should contain a next and prev Node* as denoted here. ● All member variables should be private. ● Use public and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT