/**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; }
Using its Taylor-series.
write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program
This is not a question.
Here is an example program: class obj{ public: float p,n,r,si; friend void calc( obj temp); }; void calc( obj temp){ si = (p*n*r)/100; } The initialization and function calling is essential.
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; }
using function we can call the function in the program any where. by using functions we can reduce the code redundancy
float income_tax (float income, float tax_percent) { return income * tax_percent / 100; }
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.
Using its Taylor-series.
write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program
#include<
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.
By using the =MOD function.
use the rate function