/**recursive function to find square root of a double to a precision of
maxDepth = 10 decimal places
returns -1.0 when given a negative number*/
#define maxDepth 10
/*firstly find the rational part*/
double getSqrt(double numIn){
/*cant take the square root of a negitive,
and a square root should not be negative
so return -1*/
int candidate = 0;
if (numIn <0)
return -1.0;
/*try every integer until you get one whose square is higher than
the number required, and this clearly one more than the
integer part of your square root*/
do{
if (candidate *candidate *1.0 numIn)
return testVal;
if (testVal * testVal >numIn)
/*most square roots are irrational, and theirfore a maximum number of recursions
must be set, otherwise infinite recursion will occur*/
if (myDepth <maxDepth)
return getIrrational(numIn, testVal-1/10^myDepth, myDepth +1);
else
return testVal-1/10^myDepth;
}
//this can probably be improved on in terms of conciseness, but the logic is the only //way to find a sqrt without going into calculous
#include <iostream> using namespace std; int main() { int i,sum; // variables sum = 0; // initialize sum /* recursive addition of squares */ for (i = 1; i <= 30; i++) sum = sum + (i * i); cout << sum <<" is the sum of the first 30 squares." << endl; return 0; }
To calculate the execution time of a C program using different sorting algorithms, you can utilize the clock() function from the time.h library. First, include the library at the top of your program. Before calling the sorting function, capture the current clock time using clock_t start = clock();. After the sorting is complete, capture the end time with clock_t end = clock(); and calculate the execution time in seconds using (double)(end - start) / CLOCKS_PER_SEC. This will give you the time taken by the sorting algorithm to execute.
write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program
Using its Taylor-series.
This is not a question.
give an example of calculation of mathematics
#include <iostream> using namespace std; int main() { int i,sum; // variables sum = 0; // initialize sum /* recursive addition of squares */ for (i = 1; i <= 30; i++) sum = sum + (i * i); cout << sum <<" is the sum of the first 30 squares." << endl; return 0; }
To calculate the execution time of a C program using different sorting algorithms, you can utilize the clock() function from the time.h library. First, include the library at the top of your program. Before calling the sorting function, capture the current clock time using clock_t start = clock();. After the sorting is complete, capture the end time with clock_t end = clock(); and calculate the execution time in seconds using (double)(end - start) / CLOCKS_PER_SEC. This will give you the time taken by the sorting algorithm to execute.
float income_tax (float income, float tax_percent) { return income * tax_percent / 100; }
using function we can call the function in the program any where. by using functions we can reduce the code redundancy
cubic function cubic function
To calculate the distance between two points in C, you can use the distance formula, which is the square root of the sum of the squares of the differences in the x and y coordinates of the two points. This can be implemented using the sqrt() function from the cmath library.
write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program
Using its Taylor-series.
To calculate the derivative of a mathematical function using the scipy differentiation function, you can use the scipy.misc.derivative function. This function takes the mathematical function, the point at which you want to calculate the derivative, and the order of the derivative as input parameters. It then returns the numerical value of the derivative at that point.
#include<
To program a TI-83 Plus to find the area under a curve, you can use the built-in integration functionality. Start by entering the function you want to integrate using the Y= menu. Then, create a new program by accessing the PRGM menu, selecting NEW, and entering your program name. In the program, use the fnInt command to calculate the integral, specifying the function, variable, lower limit, and upper limit. Finally, display the result using the Disp command.