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...
In this problem, you will write an implementation of BubbleSort. Your function should take in a...
In this problem, you will write an implementation of BubbleSort. Your function should take in a single line representing an array of integers, and output a single line containing the list in ascending order. For example, if you receive the following input followed by a newline: 8 7 6 5 4 3 2 1 then you should display the following output followed by a newline: 1 2 3 4 5 6 7 8 Starter code for reading the input and...
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,...
//In this assignment, we implement a function that simulates the outcome of tossing of 3 dice....
//In this assignment, we implement a function that simulates the outcome of tossing of 3 dice. //We will learn how to generate random numbers, and how to seed a random number generator. //For example, we use the following code to generate a random number between 1 and 6. // rand() % 6 + 1 //The following code set the seed of the random number generator to 12345. // srand(12345); #include <stdio.h> #include <stdlib.h> #include <assert.h> //TO DO //Implement a function...
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()
In this assignment, you will be building upon the work that you did in Lab #5A...
In this assignment, you will be building upon the work that you did in Lab #5A by expanding the original classes that you implemented to represent circles and simple polygons. Assuming that you have completed Lab #5A (and do not move on to this assignment unless you have!), copy your Circle, Rectangle, and Triangle classes from that assignment into a new NetBeans project, then make the following changes: Create a new Point class containing X and Y coordinates as its...