Question
code in c please
Concepts to Practice User-written functions math.h Description For the prelab assignment, you are to write a function to calc
Functions You Must Write You may write any functions you wish to implement this program, in addition to the following functio
Sample Good Output JimR@JimRArea51 : ~/CS 1050/ FS2019/ Labs/Lab4$ compile prelab4.c JimR@JimRArea51:~/CS1050/FS 2019/ Labs/L
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

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

double MyPower(double base, int exponent){
double res = 1;
for(int i = 0; i < exponent; i++){
res *= base;
}
  
return res;
}

void DoTest(double base, int exponent){
printf("Testing %lf to the %d power:\n", base, exponent);
double resMypower = MyPower(base, exponent);
double resPow = pow(base, exponent);
  
if(resMypower != resPow){
printf("\t%lf was expected, but %d was the result.\n", base, exponent);
}
}

int main()
{
   int i,j;
for(i = 1; i < 5; i++){
for(j = 1; j < 5; j++){
DoTest(i,j);
}
}
   return 0;
}

Code screenshot:

#include < stdio.h #include <math . h> 1 2. 3 double MyPower(double base, int exponent){ 4 double res 5 1; for (int i 0; i< e

} 21 22 int main() 23 24 int i,j 25 for (i 1; i5; itt){ 26 for (j 1; j< 5; j++){ Do Test(i,j) 27 28 29 30 return 0; 31 } 32 3

Output:

PTesting 1.000000 to the 1 power: Testing 1.000000 to the 2 power: Testing 1.000000 to the 3 power: Testing 1.000000 to the 4

Add a comment
Know the answer?
Add Answer to:
code in c please Concepts to Practice User-written functions math.h Description For the prelab assignment, you...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program In this assignment you will complete the definition of two functions that...

    Write a C++ program In this assignment you will complete the definition of two functions that implement the repeated squaring algorithm described in the Stamp textbook on pages 98-99. Note that your implementation should not use the pow() function, the powl() functions, or any other built-in exponentiation functions. program4-driver.cpp - This file contains a completed main() function that serves as the driver to parse the command line, pass the values to the powerModN() function, and print the result. Make no...

  • PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end...

    PLEASE HELP!!! C PROGRAMMING CODE!!! Please solve these functions using the prototypes provided. At the end please include a main function that tests the functions that will go into a separate driver file. Prototypes int R_get_int (void); int R_pow void R Jarvis int start); void R_fill_array(int arrayll, int len); void R_prt_array (int arrayl, int len) void R-copy-back (int from[], int to [], int len); int R_count_num (int num, int arrayll, int len) (int base, int ex) 3. Build and run...

  • /*    Write a function that takes as an argument the value x,    and returns...

    /*    Write a function that takes as an argument the value x,    and returns the result of the expression: 20x^4 - 12x^3 - 3x^2 + 15x + 3    Note: No importing; use the power function given to you, and use it    as a reference for writing functions (note also that main itself        if a function!). */ public class Exercise9_1 { public static void main(String[] args) { int num = 5, pow = 2; System.out.println(num...

  • Objectives: - Practice designing/implementing algorithms - Practice use of functions Code and document the following functions...

    Objectives: - Practice designing/implementing algorithms - Practice use of functions Code and document the following functions using NON-RECURSIVE ITERATION only. Test the functions by calling them from a simple interactive main() function using a menu, with different values used to select the choice of function. Overall, you should have one C program (call it Lab1.c) containing one main() function and 5 other functions, where the functions are called based on an interactive user menu. The program should contain a loop...

  • Objectives: - Practice designing/implementing algorithms - Practice use of functions Code and document the following functions...

    Objectives: - Practice designing/implementing algorithms - Practice use of functions Code and document the following functions using NON-RECURSIVE ITERATION only. Test the functions by calling them from a simple interactive main() function using a menu, with different values used to select the choice of function. Overall, you should have one C program (call it Lab1.c) containing one main() function and 5 other functions, where the functions are called based on an interactive user menu. The program should contain a loop...

  • need the code in .c format #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> struct _cplx double re,...

    need the code in .c format #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> struct _cplx double re, im; // the real and imaginary parts of a complex number }; typedef struct _cplx Complex; // Initializes a complex number from two real numbers Complex CmplxInit(double re, double im) Complex z = { re, im }; return z; // Prints a complex number to the screen void CmplxPrint(Complex z) // Not printing a newline allows this to be printed in the middle of...

  • I need assistance with this code. Is there any way I can create this stack class (dealing with infix to postfix then postfix evaluation) without utilizing <stdio.h> and <math.h>? ________...

    I need assistance with this code. Is there any way I can create this stack class (dealing with infix to postfix then postfix evaluation) without utilizing <stdio.h> and <math.h>? ____________________________________________________________________________________________ C++ Program: #include <iostream> #include <string> #include <stdio.h> #include <math.h> using namespace std; //Stack class class STACK { private: char *str; int N; public: //Constructor STACK(int maxN) { str = new char[maxN]; N = -1; } //Function that checks for empty int empty() { return (N == -1); } //Push...

  • Code in C++ Function Prototypes For the second part of the lab activity, you will be...

    Code in C++ Function Prototypes For the second part of the lab activity, you will be practicing writing function prototypes. Continue working on the same project from part A. First, rewrite the code so that you are using function prototypes for the functions getNumber.getMessage, and repeat. Remember that the prototypes go at the top of the file, followed by main, then the definitions of the three functions at the end. Second, you will be creating a new function (procedure) called...

  • Create a CPP file for a C++ Program. Write exactly these functions, power(x,y) function and a...

    Create a CPP file for a C++ Program. Write exactly these functions, power(x,y) function and a print(text, number) function and the main() function. The power(x,y) function returns an integer result that is calculated by raising a number x (integer) to a power y (integer). The second argument y (exponent) of the function can not exceed 100. If the second argument exceeds 100, the function should return -1. Your power(x,y) function must be able to take either 1 or 2 integer...

  • C++ Could you check my code, it work but professor said that there are some mistakes(check...

    C++ Could you check my code, it work but professor said that there are some mistakes(check virtual functions, prin() and others, according assignment) . Assignment: My code: #include<iostream> #include<string> using namespace std; class BasicShape { //Abstract base class protected: double area; private:    string name; public: BasicShape(double a, string n) { area=a; name=n; } void virtual calcArea()=0;//Pure Virtual Function virtual void print() { cout<<"Area of "<<getName()<<" is: "<<area<<"\n"; } string getName(){    return name; } }; class Circle : public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT